PageRenderTime 142ms CodeModel.GetById 70ms app.highlight 2ms RepoModel.GetById 69ms app.codeStats 0ms

/src/LinFu.IoC/FactoryExtensions.cs

http://github.com/philiplaureano/LinFu
C# | 32 lines | 19 code | 2 blank | 11 comment | 0 complexity | c37d6ba90a2821543f29e69bc5714011 MD5 | raw file
 1using System;
 2using LinFu.IoC.Interfaces;
 3
 4namespace LinFu.IoC
 5{
 6    /// <summary>
 7    ///     Extends the <see cref="IFactory" /> instance with a few helper methods.
 8    /// </summary>
 9    public static class FactoryExtensions
10    {
11        /// <summary>
12        ///     Creates an object instance.
13        /// </summary>
14        /// <param name="factory">The target factory.</param>
15        /// <param name="serviceType">The requested service type.</param>
16        /// <param name="container">The target service contaienr.</param>
17        /// <param name="additionalArguments">The additional arguments that will be used to create the service instance.</param>
18        /// <returns>A service instance.</returns>
19        public static object CreateInstance(this IFactory factory, Type serviceType,
20            IServiceContainer container, params object[] additionalArguments)
21        {
22            var request = new FactoryRequest
23            {
24                ServiceName = null,
25                ServiceType = serviceType,
26                Arguments = additionalArguments
27            };
28
29            return factory.CreateInstance(request);
30        }
31    }
32}