c# - EF7 contructor with MVC6 dependency injection -


testing out new mvc6 , ef7 framework.

we need httpcontext in our database layers. in mvc6 have dbcontext constructor looks this:

 public class applicationdbcontext : identitydbcontext<applicationuser>     {                           httpcontext _httpcontext;                              public applicationuser currentuser { get; set; }                          public applicationdbcontext(ihttpcontextaccessor httpcontextfactory=null) 

and in our startup.cs register our di so:

services.addtransient<ihttpcontextaccessor, httpcontextaccessor>();

this works perfect...

...until doesn't. when running application, , good. however, when need apply model changes using "dnx . ef migration add" error "no parameterless constructor defined object."

ok, no problem. add additional constructur no parameters, want used migration process. however, di process registers parameterless constructor httpcontext object never passed in.

so how mvc's default di model forcefully use constructor parameter? , keep parameterless constructor migrations?

specifying constructor call when class registered not supported basic asp.net out-of-the-box di (it resolves types 1 public constructor).

you use more advanced di purpose - i.e. there alpha2 version of autofac available asp.net 5 ("autofac": "4.0.0.0-alpha2", "autofac.dnx": "4.0.0-alpha1").


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -