I am new developer using C# and I am working on a project which uses C# Unity for Dependency Injection. So the current code is like this
ISomeInterface var = new SomeConcreteType(param);
ContainerFactory.Container.RegisterInstance<ISomeInterface>(var);
Now, I want to have var1 and var2 which are of type ISomeInterface. I read online the InjectionFactory can help in this case but I am not able to figure out how that works.
Can someone explain to me how InjectionFactory works?
Like if I do this
ContainerFactory.Container.RegisterType<ISomeInterface>(
new InjectionFactory(
container => new SomeConcreteType(param1)));
ContainerFactory.Container.RegisterType<ISomeInterface>(
new InjectionFactory(
container => new SomeConcreteType(param2)));
How does then the Unity decide which one of the SomeConcreteType to inject.
stringas parameter as well, so you can name your instance. You can then later retrieve the instancy by that name.