以下があると想像してください:
public interface IocInterface1 { }
public interface IocInterface2 { }
public class IocImpl : IocInterface1, IocInterface2 { }
上記のクラス/インターフェイスのインスタンスを IoC 経由で取得しようとすると、タイプごとに 1 つのシングルトンではなく、まったく同じインスタンスが取得されることを望みます。例、b1
およびb2
以下が当てはまる必要があります。
_container.RegisterSingle<IocInterface1, IocImpl>();
_container.RegisterSingle<IocInterface2, IocImpl>();
_container.RegisterSingle<IocImpl, IocImpl>();
var test1 = _container.GetInstance<IocInterface1>();
var test2 = _container.GetInstance<IocInterface2>();
var test3 = _container.GetInstance<IocImpl>();
bool b1 = test1 == test2;
bool b2 = test2 == test3;
これは可能ですか?