自己作成サービスのデータベースコンテキストにアクセスできますか?その下のコードで、私はexampleClassServiceのコンストラクタを使ってデータベースコンテキストを設定します。 "デフォルト" のasp.netコアでconfigureServicesのサービスにデータベースコンテキストを追加する
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
//Add MVC
services.AddMvc();
//Postgres connection
var connectionString = Configuration["ConnectionStrings:PostgresConnection"];
services.AddDbContext<ApplicationDbContext>(
opts => opts.UseNpgsql(connectionString)
);
//Own created service
services.AddSingleton<ExampleClassService>(
provider => new ExampleClassService(dbcontext?);
...
}
答えのためのThxs。できます! PS:アドバイスのための興味深いノートthxs;) – Wouter