Equivalent to Bind <>. ToMethod in unity?

Is there an equivalent Ninject Factory method in unity? I am looking for an equivalent equivalent to the following example:

 Bind<IWeapon>().ToMethod(context => new Sword()); 
+4
source share
1 answer

Yes, InjectionFactory:

 container.RegisterType<IWeapon>( new InjectionFactory(con => new Sword()); 

Of course, I would not use it in this particular case, since the default behavior of the container would accomplish this with a simple type mapping. I assume your actual delegates are a bit more complicated.

+5
source

Source: https://habr.com/ru/post/1381153/


All Articles