Issue Details (XML | Word | Printable)

Key: SPRNET-133
Type: New Feature New Feature
Status: Open Open
Priority: Minor Minor
Assignee: Mark Pollack
Reporter: Nat
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
Spring.NET

Resource support inside xml configuration file

Created: 20/Jul/05 08:53 AM   Updated: 22/Jul/09 09:46 AM
Component/s: Spring-NET-CORE
Affects Version/s: 1.1 P3
Fix Version/s: None

Time Tracking:
Original Estimate: 0.38d
Original Estimate - 0.38d
Remaining Estimate: 0.38d
Remaining Estimate - 0.38d
Time Spent: Not Specified
Time Spent - Not Specified

Issue Links:
Duplicate
 
Related
 


 Description  « Hide
I'm not sure whether it has been improved in 1.0.0 or not. But as I see in 0.6.0RC3, I found that it's hard to inject something dependent on resource. For example, if I want to create an object definition for GUI, I need to be able to link "Image" object to an image/bitmap in .resx file. It seems to be fairly difficult to do. I wish to see either some additional support for this. If there is already such support, it should be documented in the manual. :)

Thanks

Rick Evans added a comment - 21/Jul/05 04:04 AM
Hi Nat

Indeed, I'd agree with you there. Support of the form you'd like is not going to be included in the 1.0 release, mainly down to the fact that you're the first person to really mention this, and well, nothing has been thrashed out as a result.

So lets thrash it out here... what would you like to see? Not so much in the sense of 'how it would work', but more from a user perspective... what would you like to be able to write to get what you want? For example (toy)...

<object id="myGuiControl" class="System.Windows.Forms...., ...">
    <property name="Image" value=" ??? what goes here ??? "/>
</object>

In the interim, you could of course use a Spring.Objects.Factory.Config.ResourceManagerFactoryObject to inject a ResourceManager instance into say a Form, and then use the GetXXX methods on the injected ResourceManager instance to grab Images, Strings, etc.

Comments?

Ciao
Rick

Rick Evans made changes - 26/Aug/05 02:15 AM
Field Original Value New Value
Assignee Mark Pollack [ mark.pollack ] Rick Evans [ springboy ]
Rick Evans added a comment - 14/Sep/05 01:23 PM
There doesn't seem to be much call for this feature at the moment, so I'm downgrading it to minor.

Rick Evans made changes - 14/Sep/05 01:23 PM
Environment
Affects Version/s 1.0 [ 10320 ]
Affects Version/s 0.6 RC3 [ 10190 ]
Description I'm not sure whether it has been improved in 1.0.0 or not. But as I see in 0.6.0RC3, I found that it's hard to inject something dependent on resource. For example, if I want to create an object definition for GUI, I need to be able to link "Image" object to an image/bitmap in .resx file. It seems to be fairly difficult to do. I wish to see either some additional support for this. If there is already such support, it should be documented in the manual. :)

Thanks
I'm not sure whether it has been improved in 1.0.0 or not. But as I see in 0.6.0RC3, I found that it's hard to inject something dependent on resource. For example, if I want to create an object definition for GUI, I need to be able to link "Image" object to an image/bitmap in .resx file. It seems to be fairly difficult to do. I wish to see either some additional support for this. If there is already such support, it should be documented in the manual. :)

Thanks
Priority Major [ 3 ] Minor [ 4 ]
Fix Version/s 1.1.0 [ 10270 ]
Aleksandar Seovic made changes - 19/Oct/05 07:02 PM
Assignee Rick Evans [ springboy ] Aleksandar Seovic [ aseovic ]
Aleksandar Seovic added a comment - 19/Oct/05 07:06 PM
I think this is a useful feature and should be included in 1.1.

We would implement it by generalizing property placeholders and using special prefix, similar to 'env' for environment variables. So, to answer your question above, this is how definition would look like:

<object id="myGuiControl" class="System.Windows.Forms...., ...">
    <property name="Image" value=" ${messageSource.myImageResource}"/>
</object>

Or something along those lines...

Mark Pollack added a comment - 28/Jan/06 09:43 PM
There should be an extensiblity mechanism based around the syntax ${resourceName:resourceDataString}. Out of the box support ${env:PATH} to resolve say the PATH environment variable and ${resource:foo.bar.gif} to get embedded gif image from a resource file.

Mark Pollack made changes - 28/Jan/06 09:43 PM
Fix Version/s 1.0.2 [ 10350 ]
Assignee Aleksandar Seovic [ aseovic ] Mark Pollack [ mark.pollack ]
Fix Version/s 1.1.0 [ 10270 ]
Mark Pollack made changes - 28/Jan/06 09:59 PM
Link This issue is duplicated by SPRNET-140 [ SPRNET-140 ]
Mark Pollack made changes - 08/Apr/06 07:16 PM
Fix Version/s 1.0.2 [ 10350 ]
Fix Version/s 1.1 P3 [ 10410 ]
Erich Eichinger added a comment - 27/Jun/06 03:38 PM
Why not simply extend the schema and allow the attribute "res" in addition to "value" and "ref". This way we could simply write

<object id="myGuiControl" class="System.Windows.Forms...., ...">
    <property name="Image" res=" http://foo.com/someimage.gif" />
</object>

and use the default IResource mechanism. Of course there should be some TypeConverter available for converting from a Stream to the targettype. But this would be required anyway.

Another idea I already implemented is to provide "ResourceAdapters". To read a file into a string-property I then wrote

<object id="myMail" type="MyNS.SimpleTemplateMailMessage" >
        <property name="TextBody">
            <object type="MyNS.StringResourceAdapter" >
                <property name="resource" value="web://./Registration_RequestPwd_MailTemplate.txt" />
                <property name="Encoding" value="iso-8859-1" />
                <property name="IsSingleton" value="false" /><!-- always reread file on every request - allows changes at runtime -->
            </object>
        </property>
</object>

Mark Pollack added a comment - 30/Jun/06 11:15 AM
Hi,

I like the idea of a new element for common cases... I thought the common case would be to get the resource via use of a ResourceManager instead of directly from a IResource stream, but I guess both ways are equally valid, in which case how to we distinguish with just one 'res' element. The ${resourceManager: ...} , ${iresource: ...} approach gives a little mini namespace inside.

The adapter approach is pretty nice, and if we provide custom schema, it could be very terse for common cases as well as not requiriing a change to the core schema.

i.e.

<object id="myMail" type="MyNS.SimpleTemplateMailMessage" >
        <property name="TextBody">
            <resource url="web://./Registration_RequestPwd_MailTemplate.txt"
                               encoding="iso-8859-1"
                               isSingleton="false"/>
        </property>
</object>

Cheers,
Mark

Mark Pollack added a comment - 30/Jun/06 04:27 PM
Hi,
Actually I realize (doh!) that that mixing and matching of the schema isn't possible...so nix what I suggested.
Mark

Erich Eichinger added a comment - 01/Jul/06 05:59 AM
Your proposal also still lacks an important information: How do you know, how to convert a stream to the desired type?

The adapter approach solves this by having to choose the right adapter. I guess providing some common adapters will satisfy 90% of the needs - of course it's more xml to write.

I don't know ResourceManagers yet. But shouldn't it be possible by introducing a new "resx" IResource-protocol?

Erich

Bruno Baia added a comment - 03/Jul/06 05:41 PM
I think we wanted to resolve this extending PropertyPlaceholderConfigurer like explained in the duplicated issue :
http://opensource.atlassian.com/projects/spring/browse/SPRNET-140

[quote="Aleks"]
basically, the idea is that properties used by the PropertyPlaceholderConfigurer can come from different sources
config file is just one source
others could be environment variables, registry, resources...
and users should be able to implement custom ones as well that will allow them to get properties from database, for example
so we need a IPropertySource abstraction and several implementations of it
[/quote]

Bruno Baia made changes - 10/Aug/06 04:03 AM
Fix Version/s 1.0.3 [ 10462 ]
Fix Version/s 1.1 P3 [ 10410 ]
Craig Walls added a comment - 19/Sep/06 03:08 PM
FWIW, I ran into the same problem. I needed an ImageListStreamer to be injected from a resource into an object. I used a factory object:

    class ResourceObjectFactoryObject:IFactoryObject,IInitializingObject,IMessageSourceAware
    {
        private Type _objectType;
        private string _resourceName;
        private IMessageSource _messageSource;

        public Type ObjectType
        {
            get { return _objectType; }
            set { _objectType = value; }
        }
        
        public string ResourceName
        {
            set { _resourceName = value; }
        }

        public bool IsSingleton
        {
            get { return true; }
        }

        public object GetObject()
        {
            return _messageSource.GetResourceObject(_resourceName);
        }

        public void AfterPropertiesSet()
        {
            if(_resourceName == null)
            {
                throw new ObjectInitializationException("ResourceName must be set.");
            }
            
            if(_messageSource == null)
            {
                throw new ObjectInitializationException("MessageSource must be set.");
            }

            if(_objectType == null)
            {
                throw new ObjectInitializationException("ObjectType must be set.");
            }
            
        }

        public IMessageSource MessageSource
        {
            set { _messageSource = value; }
        }
    }

It depends upon a message source being configured, but aside from that, it's fairly straight-foward. I just configure the ResourceName and ObjectType properties...then wire the factory object into the property that needs to be injected with the resource object.


Mark Pollack made changes - 03/Dec/06 11:27 AM
Affects Version/s 1.0 [ 10320 ]
Affects Version/s 1.1 P3 [ 10410 ]
Fix Version/s 1.0.3 [ 10462 ]
Fix Version/s 1.1 RC1 [ 10411 ]
Aleksandar Seovic made changes - 24/Jan/07 10:14 AM
Assignee Mark Pollack [ mark.pollack ] Aleksandar Seovic [ aseovic ]
Mark Pollack added a comment - 03/Aug/07 06:12 PM
factory object implementation with a custom schema (+ ability to mix different schema's in def of object definition) seem the way to go here.

Mark Pollack made changes - 03/Aug/07 06:12 PM
Fix Version/s 1.1.0 [ 10270 ]
Fix Version/s 1.1 RC1 [ 10411 ]
Mark Pollack added a comment - 15/Nov/07 04:46 PM
add this approach in the docs and defer providing an implementation to 1.2

Mark Pollack made changes - 16/Nov/07 10:44 AM
Original Estimate 0.38d [ 10800 ]
Remaining Estimate 0.38d [ 10800 ]
Mark Pollack made changes - 16/Nov/07 10:44 AM
Fix Version/s 1.2.0 [ 10271 ]
Fix Version/s 1.1.0 [ 10270 ]
Mark Pollack made changes - 16/Nov/07 10:45 AM
Link This issue is related to SPRNET-775 [ SPRNET-775 ]
Mark Pollack made changes - 15/Sep/08 10:12 PM
Fix Version/s 1.2.0 [ 10271 ]
Mark Pollack made changes - 16/Sep/08 08:52 AM
Fix Version/s 1.2.0 RC1 [ 10906 ]
Erich Eichinger made changes - 08/Oct/08 07:28 AM
Assignee Aleksandar Seovic [ aseovic ] Mark Pollack [ mark.pollack ]
Erich Eichinger added a comment - 08/Oct/08 07:37 AM
what namespace are you thinking of? having a separate ns for only 1 use case seems a bit too much?

adding Craig's ResourceObjectFactoryObject definitely makes sense - as well as some IResourceAdapters (which essentially are the same as factory objects):

adapt IResource -> String
adapt IResource -> Image
...

is there maybe a solution to add custom type converters for IResource -> Type X?

Mark Pollack made changes - 13/Oct/08 10:05 PM
Fix Version/s 1.2.0 RC1 [ 10906 ]
Fix Version/s 1.2.0 [ 10271 ]
Erich Eichinger added a comment - 05/Nov/08 10:47 AM
Graig's ResourceObjectFactoryObject is certainly appealing, but how does one access e.g. System.Web.UI.Page resources from an App_LocalResources folder in webapps? Need to put some more time on investigation here

Erich Eichinger made changes - 05/Nov/08 10:47 AM
Fix Version/s 1.2.0 [ 10271 ]
Fix Version/s 1.2.1 [ 11116 ]
Mark Pollack made changes - 22/Jul/09 09:46 AM
Fix Version/s 1.3.0 RC1 [ 11116 ]