Hello Krzysztof,
(hehe, luckily I don’t have to pronounce it, I only have to type it! J) This seems like a way forward – will check it out, thanks! Regarding the reflection stuff, it’s more of an “application domain” thing in this case. What we’re building is a general application framework (built on top of Castle Windsor), so I don’t know if doing it with Windsor is an option. Anyway, thank you again for your helpfulness and friendly attitude towards your users. Best regards, Per From: [email protected] [mailto:[email protected]] On Behalf Of Krzysztof Kozmic Sent: den 8 november 2010 12:15 To: [email protected] Subject: Re: Dependencies on the IoC container vis-a-vis the Typed Factory facility - the good, the bad, the ugly again... Per, in broad strokes as you describe the scenario it does look like a job for typed factory. Typed factories are generally tool you use in places when you need to obtain a component in another component _after_ it was created which obviosuly looks like the case here. By default Windsor uses return type (and optionally method name) to look up component to resolve. If you're passing the type as argument you will have to override the default convention which is very simple. The documentation http://stw.castleproject.org/Windsor.Typed-Factory-Facility-interface-based -factories.ashx?NoRedirect=1#Custom_codeITypedFactoryComponentSelectorcodes _15 has an example of using string argument to lookup components by name, in your case code will be pretty much identical, with difference being you override GetComponentType instead. I'm not sure what you actually do in the Populate the object properties using the .NET Reflection API part. You can adjust the typed factory method's signature and override GetArguments in your selector to have Windsor do this part of the work for you as well if feasable. cheers, Krzysztof the tunguebreaker. On 08/11/2010 7:48 PM, Lundberg, Per wrote: Hi there, Ive been reading this blog post http://kozmic.pl/archive/2009/12/24/castle-typed-factory-facility-reborn.as px by Krzysztof now (man, your name has too many consontants in it J) and have some questions, of a design pattern character. What were after is something like this. Historically, weve had code that looked something like this: ///<summary> ///Mapssearchresulttextstringstocorrespondingentityobjects. ///</summary> publicclassSearchResultItemMapper { IObjectFactory_objectFactory; ///<summary> ///Createsanewinstanceoftheclass. ///</summary> ///<paramname="objectFactory">TheObjectFactoryinstanceweareusing.</param> publicSearchResultItemMapper(IObjectFactoryobjectFactory) { _objectFactory=objectFactory; } ///<summary> ///Mapsanentityfromaheaderstring. ///</summary> ///<paramname="typeName">Thenameofthetypetowhichweshouldmapthisstring.</par am> ///<paramname="headerString">Theheaderstring.</param> ///<returns>Theentityobject.</returns> publicobjectMapEntityFromHeaderString(Typetype,stringheaderString) { //Createtheentityobjectwhichwillbepopulatedwithdata. objectentityObject=_objectFactory.CreateObject(type); //[snip] Populate the object properties using the .NET Reflection API. } What this code did was basically mapping up a given header string (well, serialized object data is a better name for it) to an entity object of ours. We used a custom class called the ObjectFactory for this. This was before we started using the Castle Windsor container; we were using Unity Container for the IoC stuff and combined it with Dynamic Proxy to be able to get the proxying done. Now, were in a more pure Castle Windsor mode, and as you are suggesting, using the container from our components indicate that we are doing something wrong J What we do need to be able to do in this code is to create objects, of any type (well, deriving from a certain base class of ours all such entities are registered in the container, using mass-registration). We then use reflection to populate these objects with data. This allows the application to be pretty dynamic and not too hard-wired (well yeah, you get the general picture). So what do we do? Is this a scenario for the Typed Factory facility? As you see, were not getting called as a generic method, with a type argument, but rather with a System.Type argument. This is because we are deducing the type dynamically, depending on the data from an XML configuration file or something like that. Please, any advice will be welcome. This is the first application were upgrading to this new version of our application framework, so the design pattern should be set up properly for future projects as well. Thanks in advance! Best regards, Per -- You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.
