Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. protected void Application_Start()
  2. {
  3. AreaRegistration.RegisterAllAreas();
  4.  
  5. RegisterGlobalFilters(GlobalFilters.Filters);
  6. RegisterRoutes(RouteTable.Routes);
  7. RegisterCastle();
  8.  
  9. }
  10. private void RegisterCastle()
  11. {
  12. _container = new WindsorContainer();
  13. _container.Install(FromAssembly.InDirectory(new AssemblyFilter(HttpRuntime.BinDirectory)));
  14. ControllerBuilder.Current.SetControllerFactory(new WindsorControllerFactory(_container.Kernel));
  15. }
  16.  
  17. kernel.Load(AppDomain.CurrentDomain.GetAssemblies());
  18.  
  19. using System;
  20. using System.Collections.Generic;
  21. using System.Linq;
  22. using System.Web;
  23. using System.Web.Mvc;
  24. using Castle.Facilities.TypedFactory;
  25. using Castle.MicroKernel;
  26. using Castle.MicroKernel.Registration;
  27. using Castle.Windsor;
  28. using Castle.Windsor.Installer;
  29. using DFW.Domain.Interfaces;
  30. using UI.App_Start;
  31. using UI.Windsor;
  32.  
  33. [assembly: WebActivator.PostApplicationStartMethod(typeof(Bootstrapper), "Wire")]
  34. [assembly: WebActivator.ApplicationShutdownMethod(typeof(Bootstrapper), "DeWire")]
  35.  
  36. namespace UI.App_Start
  37. {
  38. public class Bootstrapper
  39. {
  40. private static readonly IWindsorContainer Container = new WindsorContainer();
  41. public static void Wire()
  42. {
  43. //To be able to inject IEnumerable<T> ICollection<T> IList<T> T[] use this:
  44. //container.Kernel.Resolver.AddSubResolver(new CollectionResolver(container.Kernel, true));
  45. //Documentation http://docs.castleproject.org/Windsor.Resolvers.ashx
  46.  
  47. //To support typed factories add this:
  48. Container.AddFacility<TypedFactoryFacility>();
  49. Container.Register(Component.For<IServiceFactory>().AsFactory().LifestyleTransient());
  50. //Documentation http://docs.castleproject.org/Windsor.Typed-Factory-Facility.ashx
  51.  
  52. Container.Install(FromAssembly.This()).Install(FromAssembly.Named("APP.Infrastructure.DependencyResolution"));
  53. var controllerFactory = new WindsorControllerFactory(Container.Kernel);
  54. ControllerBuilder.Current.SetControllerFactory(controllerFactory);
  55. }
  56.  
  57. public static void DeWire()
  58. {
  59. Container.Dispose();
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement