Search code examples
data-access-layerrestier

Feed restier from external DBcontext


I have separate DAL and need to feed restier controller from it. Is it possible to use dbcontext from another assembly ?

also I am trying it but getting error on connection string to dbcontext.


Solution

  • Of course it is possible. You just have to register your dbContext as service in serviceCollection. Your problem with connection string isn't related to RESTier at all.

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