Azure Functions 中的 DI

0

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

The End

相关推荐

Func<string,string> 有什么区别?和委托?
What is the difference between Funclt;string,stringgt; and delegate?(Funclt;string,stringgt; 有什么区别?和委托?)...
2023-11-11 C#/.NET开发问题
3

ASP.NET MVC 中的 <%: 和 <%= 有什么区别?
What is the difference between lt;%: and lt;%= in ASP.NET MVC?(ASP.NET MVC 中的 lt;%: 和 lt;%= 有什么区别?)...
2023-11-10 C#/.NET开发问题
0

标签系统的 linq 查询 - 搜索多个标签
linq query for tag system - search for multiple tags(标签系统的 linq 查询 - 搜索多个标签)...
2023-11-10 C#/.NET开发问题
0

论坛标签.实施它们的最佳方法是什么?
Forum tags. What is the best way to implement them?(论坛标签.实施它们的最佳方法是什么?)...
2023-11-10 C#/.NET开发问题
1

html 脚本标签未使用类型 javascript <script type="text
html script tag not using type javascript lt;script type=quot;text/htmlquot;gt;?(html 脚本标签未使用类型 javascript lt;script type=quot;text/htmlgt;gt;?)...
2023-11-10 C#/.NET开发问题
6

ASP.NET 控件到 HTML 标记等效
ASP.NET Control to HTML tag equivalent(ASP.NET 控件到 HTML 标记等效)...
2023-11-10 C#/.NET开发问题
32