|
Rick Evans made changes - 26/Aug/05 02:15 AM
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
Aleksandar Seovic made changes - 19/Oct/05 07:02 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... 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
Mark Pollack made changes - 28/Jan/06 09:59 PM
Mark Pollack made changes - 08/Apr/06 07:16 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> 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 Hi,
Actually I realize (doh!) that that mixing and matching of the schema isn't possible...so nix what I suggested. Mark 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 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
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
Aleksandar Seovic made changes - 24/Jan/07 10:14 AM
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
add this approach in the docs and defer providing an implementation to 1.2
Mark Pollack made changes - 16/Nov/07 10:44 AM
Mark Pollack made changes - 16/Nov/07 10:44 AM
Mark Pollack made changes - 16/Nov/07 10:45 AM
Mark Pollack made changes - 15/Sep/08 10:12 PM
Mark Pollack made changes - 16/Sep/08 08:52 AM
Erich Eichinger made changes - 08/Oct/08 07:28 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
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
Mark Pollack made changes - 22/Jul/09 09:46 AM
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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