StructureMap singleton usage (A class implementing two interface)

后端 未结 4 431
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 04:46
public interface IInterface1
{
}

public interface IInterface2
{
}

public class MyClass : IInterface1, IInterface2
{
}

...

ObjectFactory.Initialize(x =>
{
             


        
4条回答
  •  不知归路
    2020-12-01 04:49

    I would register the MyClass itself and then pull that out of the context for the Use statements of the individual interfaces.

    ForSingletonOf().Use();
    
    For().Use(ctx => ctx.GetInstance());
    For().Use(ctx => ctx.GetInstance());
    

提交回复
热议问题