【发布时间】:2017-02-14 14:12:39
【问题描述】:
我错过了一些东西。我似乎注册正常,但我的决心因以下异常而崩溃。
{"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")));
【问题讨论】:
标签: prism ioc-container