У меня есть следующий код:
public interface IGenericDao<TEntity> where TEntity : IEntity { }
public interface IEntity { }
public abstract class AbstractEntity : IEntity {}
public interface IMasterEntity : IEntity {}
public interface IDynamicEntity : IEntity {}
public class Client : AbstractEntity , IMasterEntity {}
public class MasterEntityHandler<TEntity> : IGenericDao<TEntity>, IDisposable where TEntity : IMasterEntity {}
public class DynamicEntityHandler<TEntity> : IGenericDao<TEntity>, IDisposable where TEntity : IDynamicEntity {}
В контейнере Unity я сделал регистрацию как:
container.RegisterType<IGenericDao<IMasterEntity>, MasterEntityHandler<IMasterEntity>>(new ContainerControlledLifetimeManager());
container.RegisterType<IGenericDao<IDynamicEntity>, MasterEntityHandler<IDynamicEntity>>(new ContainerControlledLifetimeManager());
При попытке решить с помощью класса Client с помощью
container.Resolve<IGenericDao<Client>>();
Я получаю сообщение об ошибке
---> System.Reflection.TargetInvocationException: Исключение было сгенерировано целью вызова. --->
Unity.ResolutionFailedException: текущий тип,
Interface.IGenericDao`1 [Клиент]
является интерфейсом и не может быть построен Вы пропустили тип
отображение
Пробовал и эту регистрацию тоже, но все та же ошибка:
container.RegisterType(typeof(IGenericDao<IMasterEntity>),typeof(MasterEntityHandler<>)
, new ContainerControlledLifetimeManager());
container.RegisterType(typeof(IGenericDao<IDynamicEntity>),typeof(DynamicEntityHandler<>)
, new ContainerControlledLifetimeManager());
а также:
container.RegisterType(typeof(IGenericDao<>),typeof(MasterEntityHandler<IMasterEntity>)
, new ContainerControlledLifetimeManager());
container.RegisterType(typeof(IGenericDao<>),typeof(DynamicEntityHandler<IDynamicEntity>)
, new ContainerControlledLifetimeManager());