以下のコードがあり、ジェネリックの異なるバリアントごとにシングルトンを登録したいと考えています。これは可能ですか?現在、同じオブジェクト タイプではないため、アサーションは失敗します。
public interface IGenericClass<T>
{
string GetToString();
}
public class GenericClass<T> : IGenericClass<T>
{
public string GetToString()
{
return typeof (T).FullName;
}
}
[Test]
public void test()
{
var container = new Container();
container.RegisterOpenGeneric(
typeof(IGenericClass<>),
typeof(GenericClass<>));
var instance1 = container.GetInstance<IGenericClass<double>>();
var instance2 = container.GetInstance<IGenericClass<double>>();
//this should assert true
Assert.IsTrue(object.ReferenceEquals(instance1, instance2));
}