我想写一个JobActivator HangFire使用ServiceStack IoC和我无法解决类型。我相信对于那些对泛型有更多经验的人来说,这将是一个简单的答案。如何解决类型使用ServiceStack Funq IoC
我传递中的容器,从HostContext.Container来
using Hangfire;
using System;
using System.Collections.Generic;
using System.Linq;
using ServiceStack;
namespace Common.Hangfire
{
public class FunqJobActivator : JobActivator
{
private Funq.Container _container;
public FunqJobActivator(Funq.Container container)
{
if (container == null)
{
throw new ArgumentNullException("container");
}
_container = container;
}
public override object ActivateJob(Type type)
{
return _container.Resolve<type>(); //** this doesn't compile
}
}
}
Funq'的'作为IoC框架的选择是在这种情况下不幸。许多IoC框架将提供一个'Resolve'方法,它接受'Type'作为它的参数。我不相信Funq。它依赖泛型方法参数来获取类型。 – Alex