Paramaterized抽象工厂在Autofac抽象、工厂、Paramaterized、Autofac

2023-09-03 17:48:39 作者:遗憾.

我希望能够在Autofac具有以下属性寄存器一个工厂组件:

I want to be able to register a factory component in Autofac with the following properties:

工厂必须采取的参数(在这种情况下,字符串),并返回,是专门有关该字符串组件实例 在组件的生命周期必须是InstancePerLifetimeScope 中排名第2的含义是,与特定的参数值工厂的第二个呼叫将一生范围内返回相同的组件实例。

我已经能够通过编写一些code充当一个名字注册的生命周期范围内,保持已经创建了名称和组件实例的字典来实现这一目标。这工作,但我怀疑有可能是一个办法使用一些autofac注册魔法来做到这一点,但我还没有破解它。任何想法?

I have been able to achieve this by writing some code which acts as a "name registry" within the lifetime scope, keeping a dictionary of names and component instances which have been created. This works, but I suspect there might be a way to do this using some autofac registration magic, but I haven't been to crack it yet. Any ideas?

谢谢!

推荐答案

这听起来像你想的Autofac的指数。

It sounds like you want an Autofac Index.