2016-10-06 3 views
0

Мне что-то не хватает. Кажется, я зарегистрировался нормально, но мое решение взорвалось следующим исключением.Как обернуть Hinging с помощью HingeProcess?

{ «Тип Test.Interfaces.IProcess`1 является открытым универсальным типом Открытого общего типа не может быть разрешен \ г \ nParameter имени:.. Т»}

Как обернуть шарнирный с HingeProcess , Я думал, что RegisterInstance позаботился об этом?

public interface IProcess<T> where T : class 
{ 
    Expression<Func<T, bool>> Expression { get; set; } 
    T Entity { get; set; } 
} 

public class HingingProcess<T> : IProcess<T> where T : class 
{ 
    public Expression<Func<T, bool>> Expression { get; set; } 
    public T Entity { get; set; } 

    public HingingProcess(T entity) 
    { 
     Entity = entity; 
    } 
} 

container.RegisterType(typeof(IProcess<>), typeof(HingingProcess<>), "HingeProcess", 
        new InjectionConstructor(new GenericParameter("T", "entity"))); 
     Hinging a = new Hinging(); 
     container.RegisterInstance<Hinging>("entity", a); 

var pp = container.Resolve(typeof(IProcess<>), "HingeProcess", new ParameterOverrides[] { }); 

Мысль, возможно, это сработает, но не сможет зарегистрироваться.

  container.RegisterType<object, Hinging>("hinge"); 

     container.RegisterType(typeof(IProcess<>), typeof(HingingProcess<>), "HingeProcess", 
     new InjectionConstructor(new GenericParameter("entity", "hinge"))); 

ответ

0

Вы должны указать тип IProcess при решении

var container = new UnityContainer(); 
container.RegisterType(typeof(IProcess<>), typeof(HingingProcess<>), "HingeProcess",new InjectionConstructor(new GenericParameter("T", "entity"))); 
Hinging a = new Hinging();   
var pp = container.Resolve(typeof(IProcess<Hinging>), "HingeProcess", new ParameterOverride("entity", a)); 
Смежные вопросы