PageRenderTime 122ms CodeModel.GetById 61ms app.highlight 1ms RepoModel.GetById 59ms app.codeStats 0ms

/src/SampleLibrary/IOC/SampleOpenGenericFactory.cs

http://github.com/philiplaureano/LinFu
C# | 19 lines | 17 code | 2 blank | 0 comment | 0 complexity | 6ea101046044165d351ec7c62bd64d48 MD5 | raw file
 1using System;
 2using LinFu.IoC.Configuration;
 3using LinFu.IoC.Interfaces;
 4
 5namespace SampleLibrary
 6{
 7    [Factory(typeof(ISampleGenericService<>))]
 8    public class SampleOpenGenericFactory : IFactory
 9    {
10        public object CreateInstance(IFactoryRequest request)
11        {
12            var serviceType = request.ServiceType;
13            var typeArgument = serviceType.GetGenericArguments()[0];
14            var resultType = typeof(SampleGenericImplementation<>).MakeGenericType(typeArgument);
15
16            return Activator.CreateInstance(resultType);
17        }
18    }
19}