.NET Core get connection string from appsettings.json

后端 未结 4 2037
执笔经年
执笔经年 2020-12-16 11:22

I develop a simple web app and, in the future, I want to do it as multi-tenancy.

So I want to write the connection string straight into OnConfiguring me

4条回答
  •  佛祖请我去吃肉
    2020-12-16 12:05

    So I want to write the connection string straight into OnConfiguring method:

    How can I extract connection string from appsettings.json into ApplicationContext class?

    I wouldn't like to create any constructors for ApplicationContext class.

    You could use Options Pattern via IOptions but the easiest way is using DI in ApplicationContext constructor ;)

    Follow below articles, please:

    • Example of using IOptions,
    • Using Options and configuration objects,
    • IOptions Interface,

提交回复
热议问题