c# - Register an interface with Autofac? -


i have class based on dbcontext , it's generated automatically ef designer (currently using database first). dbcontext in own assembly called 'model'.

public partial class mycontext : dbcontext {} 

i have code in partial class , implementing interface:

public interface imycontext {     int commit();     task<int> commitasync(cancellationtoken ct); }  public partial class mycontext : imycontext {} 

i have unit of work , generic repository. these classes in separater assembly called 'dal'

public interface iunitofwork<tcontext> : idisposable tcontext : imycontext {     int commit();     task<int> commitasync(cancellationtoken ct); }  public interface irepository<t> t : class {}  public abstract class repository<tcontext, t> : irepository<t> tcontext : imycontext t : class, ientity 

and have services, in yet assembly called 'services'.

public class loginservice : baseservice, iloginservice {     public loginservice(ilogservice logservice,                         iunitofwork<imycontext> unitofwork)          : base(logservice, unitofwork)      { } } 

i need register imycontext autofac:

builder.registertype(typeof(mycontext))        .as(typeof(imycontext))        .instanceperrequest(); 

but if above registration, error dbcontext not known. because don't have (and don't want/need) reference entity framework in webapi project

can still register above interface without requiring reference ef? alternatives?

seems error because mycontext not registered dbcontext.

an alternative might create autofac module lives inside dal assembly , responsible registrations related mycontext. autofac registrations in webapi project consist of registering module opposed registering individual types.

this mean need reference autofac in dal assembly. also, i'm not entirely familiar autofac's more recent versions, i'm not sure if you'll run issues trying register instanceperrequest scope outside of web project.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -