I am trying to automatically defines generic in generic restriction, but I am unable to do it.
Here is my code and want I can do and what I want to do:
public class DummyEntity : IDbId { public int Id { get; set; } }
public class BaseServices<TEntity> { }
public class SomeServices : BaseServices<DummyEntity>{ }
public class BaseController<TService, TEntity> : Controller where TService : BaseServices<TEntity> { }
//I can do this.
public class SomeController : BaseController<SomeServices, DummyEntity> { }
//but I want this.
public class Some2Controller : BaseController<SomeServices> { }
Is this possible? I do not want to pass also DummyEntity
to BaseController
, since DummyEntity
can be extracted from SomeServices<DummyEntity>
.
Creating non-generic BaseService
is not an option.
I tried this but it does not compile:
public class Base2Controller<TServices> : Controller where TServices : BaseServices<> { }
I think this question is very similar (if not the same) to this one, but I am hoping this is not the case or if it is, some new C# feature was introduce in last 8 years.