I have not tried this yet, but it seems that the solution is given in the documentation for ASP.NET 5 Injection Dependency in the section " Replacing the default service container ".
Examples for AutoFac, but the same three steps can be applied to Castle Windsor, I believe:
Add the appropriate container container to the dependency property in project.json.
"dependencies" : {
"Autofac": "4.0.0-beta8",
"Autofac.Framework.DependencyInjection": "4.0.0-beta8"
},
Then, in Startup.cs, configure the container in ConfigureServicesand change this method to return IServiceProviderinstead of void:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterModule<DefaultModule>();
containerBuilder.Populate(services);
var container = containerBuilder.Build();
return container.Resolve<IServiceProvider>();
}
Finally, configure Autofac as usual in the DefaultModule:
public class DefaultModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<CharacterRepository>().As<ICharacterRepository>();
}
}
source
share