Azure Functions 中的 DI [英] DI in Azure Functions

查看:21
本文介绍了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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆