I want to be able to register a factory component in Autofac with the following properties:
- factory must accept a parameter (in this case, a string) and return an instance of the component that is specifically associated with this string
- Component Lifetime Must Be InstancePerLifetimeScope
- Implication No. 2 is that the second factory call with a specific parameter value returns the same component instance within its service life.
I was able to achieve this by writing code that acts as a βname registryβ within the scope, while maintaining a dictionary of the names and instances of the components that were created. This works, but I suspect there might be a way to do this using some autofac registry magic, but I have not tried to crack it yet. Any ideas?
Thank!
source
share