开发者

Using abstract factory as injectionfactory in Unity?

开发者 https://www.devze.com 2023-03-02 05:33 出处:网络
I have an abstract factory registered for injection in some controller instances. Can I register that abstract factory and use it as an injection factory?

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

This is what I h开发者_开发百科ave:

public interface ILevelFactory
{
    Levels Create();
}

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

Desired situation:

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

In short, I want to get rid of the StaticLevelFactory.


If your ILevelFactory is properly registered:

RegisterType<Levels>(new InjectionFactory((c) => c.Resolve<ILevelFactory>().GetLevels()))
0

精彩评论

暂无评论...
验证码 换一张
取 消