Kephas如何与ASP.NET Core集成? [英] How does Kephas integrate with ASP.NET Core?

查看:94
本文介绍了Kephas如何与ASP.NET Core集成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,Kephas不提供自己的DI容器,而是在现有适配器上构建适配器(无法在带有Kephas的开放式通用服务中使用构造函数.

So much I could understand, Kephas does not provide its own DI container, but it builds adapters on existing ones (Kephas has its own dependecy injection container. Why another framework, why not use an existing one?). Existing adapters are for System.Composition (MEF2) and, as I learned recently, for Autofac (starting with version 6.5.0, Cannot use constructors in open generic services with Kephas).

但是,ASP.NET带有自己的DI容器实现.在这方面,现在是否可以将Kephas与ASP.NET Core一起使用,如果可以,如何使用?

However, ASP.NET comes with its own implementation of a DI container. In this regard, is it possible to use Kephas with ASP.NET Core now, and if yes, how?

推荐答案

从版本6.5.0开始,Kephas还提供了一个ASP.NET Core适配器,因此,是的,不久之后就可以将Kephas与ASP.NET一起使用了.核.但是,内置的依赖注入不具有Kephas所需的所有功能,即命名元数据和延迟实例化.也将有一个适用于Microsoft.Extensions.DependencyInjection的适配器,但没有上述功能,因此我并不推荐这样做.Autofac适配器是推荐的适配器(如果Microsoft ASP.NET Core在高级方案中推荐使用该适配器).

Starting with version 6.5.0, Kephas will provide also an ASP.NET Core adapter so, yes, it will be shortly possible to use Kephas with ASP.NET Core. However, the built-in Dependency Injection does not have all the features Kephas requires, naming metadata and lazy instantiation. There will also be an adapter for Microsoft.Extensions.DependencyInjection, but without the aforementioned functionality, so I do not really recommend it. The Autofac adapter is the recommended one (event the Microsoft ASP.NET Core recommends it for advanced scenarios).

另一方面,您可以让Kephas使用MEF2或Autofac管理其依赖关系,并向ASP.NET Core提供一个服务提供商,该服务提供商将默认的(或您选择的一个)和来自Kephas的一个集成在一起.这具有以下缺点:

On the other hand, you could let Kephas manage its dependencies using MEF2 or Autofac and provide to ASP.NET Core a service provider aggregating the default one (or the one of your choice) and the one from Kephas. This has the following drawbacks:

  1. 您将最终得到两个容器.

  1. You will end up with two containers.

Kephas容器将无法访问ASP.NET Core提供的服务.

The Kephas container will not have access to the services provided by ASP.NET Core.

这篇关于Kephas如何与ASP.NET Core集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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