How to pass Owin context to a Repo being injected into Api controller

后端 未结 4 484
挽巷
挽巷 2020-12-08 21:52

I\'ve got a MVC WebApi owin (soft hosted) project, that uses Unity for resolving controller dependencies

which look like this

public class PacientaiC         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 22:05

    I think the problem is that HttpContext does not exist at the time Startup is called, so what you probably need, is to have a Func instead, like this:

    public class PacientasEntityRepo:IEntityRepo,IDisposable
    {
        public PacientasEntityRepo(Func ctx)
        {
        .........
    

    and then change the code in Startup to this:

    Container.RegisterType(new InjectionFactory(() => HttpContext.Current.GetOwinContext()));
    

提交回复
热议问题