Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Enterprise Library Unity vs Other IoC Containers

By: a guest on Feb 27th, 2012  |  syntax: None  |  size: 1.42 KB  |  views: 17  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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>();