Reputation: 1333
I'm trying to create a new Web API based on the ASP.Net 5 Web API template in VS2015, with DryIoc at container. I've created a new Web API project and installed the DryIoc using package-manager
Install-Package DryIoc.Dnx.DependencyInjection -Pre
but I'm not sure how to wire up the container... haven't been able to find any 'Web API' samples showing that....
Any help would be greatly appreciated
Upvotes: 1
Views: 1079
Reputation: 1333
I've figured it out now... The default startup.cs file contains:
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddApplicationInsightsTelemetry(Configuration);
services.AddMvc();
}
but it has to be replace with:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMvc();
var container = new Container().WithDependencyInjectionAdapter(services);
container.Register<IRepository, Repository>(Reuse.Singleton);
var serviceProvider = container.Resolve<IServiceProvider>();
return serviceProvider;
}
also the ' System.Runtime.Extensions >= 4.0.11-rc2-23706' error can just be ignored
Upvotes: 4
Reputation: 4950
I don't have a specific WebApi sample at the moment. But WebApi and Mvc are "unified" in AspNetCore, and I do have primitive Mvc sample. Hope it helps.
Btw, I am open for ideas / PRs how to improve it further.
Upvotes: 0