我有一个派生自 DbConfiguration 的类,用于执行任何连接弹性策略。
我在 global.asax.cs 的 Application_Start 中的 Web 角色中调用它。
如果是 worker 角色,我在哪里调用相同的函数?
最佳答案
在应用程序的 app.config 中(我的应用程序名为“WebJob”),其中包含标签 --EntityFramework-- ... 添加 codeConfigurationType,如下所示:
<entityFramework codeConfigurationType="WebJob.EFConfigDB, WebJob">
... your EF config here ...
</entityFramework>
EFConfigDB 是我从 DbConfiguration 派生的类。所以 codeConfigurationType 基本上是这样的格式,这取决于您的项目:
codeConfigurationType="<MyNameSpace>.<Derived DBConfiguration class>, <MyAssembly>"
一旦正确设置了上述内容,您的 DBConfiguration 派生类的无参数构造函数将被自动调用。
关于.net - azure辅助角色中的DbConfiguration.SetConfiguration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25723978/