I haven't tried this yet, but it seems the solution is given in the documentation for ASP.NET 5 Dependency Injection under "Replacing the default services container".
The examples there are for AutoFac but the same three steps can be applied to Castle Windsor I believe:
Add the appropriate container package(s) to the dependencies property in project.json.
"dependencies" : {
"Autofac": "4.0.0-beta8",
"Autofac.Framework.DependencyInjection": "4.0.0-beta8"
},
Next, in Startup.cs, configure the container in ConfigureServices
and change that method to return an IServiceProvider
instead of void:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
// add other framework services
// Add Autofac
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterModule<DefaultModule>();
containerBuilder.Populate(services);
var container = containerBuilder.Build();
return container.Resolve<IServiceProvider>();
}
Finally, configure Autofac as normal in DefaultModule:
public class DefaultModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<CharacterRepository>().As<ICharacterRepository>();
}
}