如何使用HingeProcess包装Hinging?

时间:2016-10-06 00:31:48

标签: prism ioc-container

我错过了什么。我似乎正在注册,但我的决心因以下异常而爆炸。

{"类型Test.Interfaces.IProcess`1是一个开放的泛型类型。无法解析开放泛型类型。\ r \ n参数名称:t"}

如何使用HingeProcess包装Hinging,我认为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")));

1 个答案:

答案 0 :(得分: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));