DI in Azure Functions(Azure Functions 中的 DI)
问题描述
我在我的 ASP.NET Web API 应用程序中使用了一些类库来处理我的所有后端内容,例如对 Azure SQL 数据库、Cosmos DB 等多个数据库的 CRUD 操作.
I have some class libraries that I use in my ASP.NET Web API app that handle all my backend stuff e.g. CRUD operations to multiple databases like Azure SQL Database, Cosmos DB, etc.
我不想重新发明轮子并能够在我在 Visual Studio 2017 中创建的新 Azure Functions 中使用它们.我所有的存储库方法都使用一个接口.那么,我将如何在我的新 Azure 函数中实现依赖注入?
I don't want to re-invent the wheel and able to use them in a new Azure Functions that I'm creating in Visual Studio 2017. All my repository methods use an interface. So, how will I implement dependency injection in my new Azure function?
我没有看到任何对 DI 的支持,但我有点困惑.Azure Functions 似乎基于与 WebJobs 相同的 SDK,我认为去年微软已经开始在 WebJobs 中支持 DI - 我很确定,因为我使用 Ninject 实现了它.
I'm not seeing any support for DI but I'm a bit confused. It appears Azure Functions are based on the same SDK as WebJobs and I think last year Microsoft had started supporting DI in WebJobs - I know for sure because I implemented it using Ninject.
有没有办法让我可以在新的 Azure Functions 项目中使用现有的库?
Is there way around this so that I can use my existing libraries in my new Azure Functions project?
推荐答案
除了服务定位器(反)模式,我还看到了这两种技术.我也询问了 Azure Functions 团队的意见.
I see these two techniques in addition to the service locator (anti)pattern. I asked the Azure Functions team for their comments as well.
https://blog.wille-zone.de/post/azure-functions-dependency-injection/
https://blog.wille-zone.de/post/azure-functions-proper-dependency-injection/
这篇关于Azure Functions 中的 DI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Azure Functions 中的 DI


基础教程推荐
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01