/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

  1. using System;
  2. using LinFu.IoC.Configuration;
  3. using LinFu.IoC.Interfaces;
  4. namespace SampleLibrary
  5. {
  6. [Factory(typeof(ISampleGenericService<>))]
  7. public class SampleOpenGenericFactory : IFactory
  8. {
  9. public object CreateInstance(IFactoryRequest request)
  10. {
  11. var serviceType = request.ServiceType;
  12. var typeArgument = serviceType.GetGenericArguments()[0];
  13. var resultType = typeof(SampleGenericImplementation<>).MakeGenericType(typeArgument);
  14. return Activator.CreateInstance(resultType);
  15. }
  16. }
  17. }