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

查看:73
本文介绍了Azure Functions中的DI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET Web API应用程序中使用了一些类库,这些类库可以处理所有后端内容,例如对多个数据库(例如Azure SQL数据库,Cosmos DB等)进行CRUD操作.

我不想重新发明轮子,也不能在我在Visual Studio 2017中创建的新Azure函数中使用它们.我的所有存储库方法都使用一个接口.那么,如何在新的Azure函数中实现依赖项注入?

我没有看到对DI的任何支持,但是有点困惑.看来Azure函数是基于与WebJobs相同的SDK的,并且我认为去年Microsoft已开始在WebJobs中支持DI-我可以肯定,因为我使用Ninject实施了它.

是否可以解决此问题,以便可以在新的Azure Functions项目中使用现有的库?

解决方案

除了服务定位器(anti)模式,我还看到了这两种技术.我也向Azure Functions团队征求了他们的意见.

https://blog.wille-zone.de/post/azure-functions-dependency-injection/

https://blog.wille-zone.de/post/azure-functions-proper-dependency-injection/

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.

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?

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.

Is there way around this so that I can use my existing libraries in my new Azure Functions project?

解决方案

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天全站免登陆