コード例 #1
0
 /// <summary>
 /// Creates an object.
 /// </summary>
 /// <param name="resolver">The resolver.</param>
 /// <param name="context">The context.</param>
 /// <returns>The created object.</returns>
 private static object CreateObject(IIoCResolver resolver, CreateObjectContext context)
 {
     object[] parameters = context.ConstructorArguments
                           .Select(type => resolver.Resolve(type))
                           .ToArray();
     return(context.Constructor.Invoke(parameters));
 }
コード例 #2
0
        /// <summary>
        /// Sets an implementation type.
        /// </summary>
        /// <typeparam name="TImplementation">The type of the implementation.</typeparam>
        /// <returns>The builder.</returns>
        public ObjectFactoryMethodBuilder ImplementationType <TImplementation>()
        {
            this.AssertFactoryMethodNotBuilt();
            CreateObjectContext context = new CreateObjectContext()
            {
                Type = typeof(TImplementation)
            };

            this.factory = resolver => CreateObject(resolver, context);
            return(this);
        }