2017-07-03 84 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(); 
      }); 
    }