Hi there,

 

I've 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 we're after is something like this. Historically, we've had code that
looked something like this:

 

    /// <summary>
    /// Maps search result text strings to corresponding entity objects.
    /// </summary>
    public class SearchResultItemMapper
    {
        IObjectFactory _objectFactory;

 

        /// <summary>

        /// Creates a new instance of the class.

        /// </summary>

        /// <param name="objectFactory">The Object Factory instance we are
using.</param>

        public SearchResultItemMapper(IObjectFactory objectFactory)

        {

            _objectFactory = objectFactory;

        }

 

        /// <summary>

        /// Maps an entity from a header string.

        /// </summary>

        /// <param name="typeName">The name of the type to which we should
map this string.</param>

        /// <param name="headerString">The header string.</param>

        /// <returns>The entity object.</returns>

        public object MapEntityFromHeaderString(Type type, string
headerString)

        {

            // Create the entity object which will be populated with data.

            object entityObject = _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, we're 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, we're 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 we're
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.

Reply via email to