# "self", (CRTP).
public class Base<TSelf> where TSelf : Base<TSelf>
{
// Make this a property if you want.
public IRepository<TSelf> GetTable()
{
return _container.Resolve<IRepository<TSelf>>();
}
}
public class Derived : Base<Derived> { }
:
IRepository<Derived> table = new Derived().GetTable();
, , . : .
, _container.Resolve, , , . :
public SomeBaseType GetTable()
{
var repositoryType = typeof(IRepository<>).MakeGenericType(GetType());
var result = _container.GetType()
.GetMethod("Resolve")
.MakeGenericMethod(repositoryType)
.Invoke(_container, null);
return (SomeBaseType) result;
}