2017-07-03 41 views
0

我有單獨的DAL,需要從它喂進restier控制器。 是否可以使用另一個程序集的dbcontext?從外部DBcontext進給restier

我也在嘗試它,但獲取連接字符串到dbcontext的錯誤。

回答

0

當然這是可能的。 您只需在serviceCollection中將您的dbContext註冊爲服務即可。 連接字符串的問題根本與RESTier無關。

public static new IServiceCollection ConfigureApi(Type apiType, IServiceCollection services) 
    { 
     return services.AddScoped<DbContext>(sp => 
      { 
      return GetYourInitializedDbContextFromAnywhereYouWant(); 
      }); 
    }