QuickLib icon indicating copy to clipboard operation
QuickLib copied to clipboard

How to use Factory and inject value in constructor in IOC?

Open jkour opened this issue 5 years ago • 2 comments

Hi, I am looking at the IOC and I want to do the following:

Say I have TBase class and TClassA and TClassB inheriting from TBase.

Now I want a factory to produce either classA or classB. Can I use Abstract Factory for this?

Thanks

jkour avatar Jun 03 '20 01:06 jkour

container.AbstractFactory<TBaseA>(TBase) creates a TBase object and returns as TBaseA container.AbstractFactory<TBaseA> creates a TBaseA object and returns as TBaseA object Both examples will resolve constructor injections of TBaseA

exilon avatar Jun 03 '20 14:06 exilon

Thanks for the explanation.

I alse see the IOC holds an IOCInjector but there is no way to pass it to the IOC. How is this meant to be used? I also see that when you resolve the objects/classes you consider params in constructors/methods but again how do you inject custom params?

jkour avatar Jun 03 '20 18:06 jkour

Closing this issue as it has been inactive for an extended period of time and there has been no recent activity. If this issue is still relevant, please feel free to reopen it with updated information.

exilon avatar May 01 '23 17:05 exilon