Using abstract factory as an injection in Unity?

I have an abstract factory registered for injection on some controller instances. Can I register this abstract factory and use it as an injection factory?

This is what I have:

public interface ILevelFactory
{
    Levels Create();
}

.RegisterType<ILevelFactory, LevelFactory>()
.RegisterType<Levels>(new InjectionFactory((c) => StaticLevelFactory.GetLevels()))

Required Situation:

.RegisterType<ILevelFactory, LevelFactory>()
.RegisterType<Levels>(*** look up and use ILevelFactory ***)

In short, I want to get rid of StaticLevelFactory.

+5
source share
1 answer

If your ILevelFactory is correctly registered:

RegisterType<Levels>(new InjectionFactory((c) => c.Resolve<ILevelFactory>().GetLevels()))
+6
source

All Articles