Using abstract factory as injectionfactory in Unit

2019-03-29 20:09发布

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 have:

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.

1条回答
冷血范
2楼-- · 2019-03-29 20:43

If your ILevelFactory is properly registered:

RegisterType<Levels>(new InjectionFactory((c) => c.Resolve<ILevelFactory>().GetLevels()))
查看更多
登录 后发表回答