Guest User

Enterprise Library Unity vs Other IoC Containers

a guest
Feb 27th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. IKernel kernel = new StandardKernel(
  2. new InlineModule(
  3. x => x.Bind<ICustomerRepository>().To<CustomerRepository>(),
  4. x => x.Bind<ICustomerService>().To<CustomerService>(),
  5. x => x.Bind<Form1>().ToSelf()
  6. ));
  7.  
  8. ObjectFactory.Initialize(x =>
  9. {
  10. x.UseDefaultStructureMapConfigFile = false;
  11. x.ForRequestedType<ICustomerRepository>()
  12. .TheDefaultIsConcreteType<CustomerRepository>()
  13. .CacheBy(InstanceScope.Singleton);
  14.  
  15. x.ForRequestedType<ICustomerService>()
  16. .TheDefaultIsConcreteType<CustomerService>()
  17. .CacheBy(InstanceScope.Singleton);
  18.  
  19. x.ForConcreteType<Form1>();
  20. });
  21.  
  22. container.RegisterType<ICustomerRepository, CustomerRepository>()
  23. .RegisterType<ICustomerService, CustomerService>();
  24.  
  25. IWindsorContainer container = new WindsorContainer();
  26. container.AddComponentWithLifestyle<ICustomerRepository, CustomerRepository>("CustomerRepository", LifestyleType.Singleton);
  27. container.AddComponentWithLifestyle<ICustomerService, CustomerService>("CustomerService",LifestyleType.Singleton);
  28. container.AddComponent<Form1>("Form1");
  29.  
  30. var builder = new ContainerBuilder();
  31. builder.Register<CustomerRepository>()
  32. .As<ICustomerRepository>()
  33. .ContainerScoped();
  34. builder.Register<CustomerService>()
  35. .As<ICustomerService>()
  36. .ContainerScoped();
  37. builder.Register<Form1>();
Add Comment
Please, Sign In to add comment