public class WindsorDependencyResolver : IDependencyResolver { private readonly IWindsorContainer _container; public WindsorDependencyResolver(IWindsorContainer container) { _container = container; } public object GetService(Type serviceType) { return _container.Kernel.HasComponent(serviceType) ? _container.Resolve(serviceType) : null; } public IEnumerable<object> GetServices(Type serviceType) { return _container.Kernel.HasComponent(serviceType) ? _container.ResolveAll(serviceType).Cast<object> () : new List<object>(); } }
The next step is to register your Dependency Resolver. I added this line to my Application_Start.
GlobalConfiguration.Configuration.ServiceResolver.SetResolver(new WindsorDependencyResolver(IocContainer));
No comments:
Post a Comment