1

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

smolesen
  • 1,153
  • 3
  • 11
  • 29

2 Answers2

4

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

smolesen
  • 1,153
  • 3
  • 11
  • 29
0

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.

dadhi
  • 4,807
  • 19
  • 25
  • Trying to make it work again, but now I get: Unable to locate Dependency System.Runtime.Extensions >= 4.0.11-rc2-23706. – smolesen Mar 24 '16 at 17:56
  • This AspNetCore proceeds moving, hopefully will stop with RC2. Meanwhile you can play with package versions, and ensure you have at least rc1-update1 installed. If your sample is on github, I can look. – dadhi Mar 24 '16 at 18:14
  • Seems like the package version is referring System.Runtime.Extensions >= 4.0.11-rc2-23706 – smolesen Mar 24 '16 at 18:27
  • It is referring 4.0.11-* – dadhi Mar 25 '16 at 03:33