从Autofac迁移如何解决?

时间:2016-07-07 02:46:32

标签: dryioc

Orchard缓存设计:

public interface ICacheManager
{
    ICache<TKey, TResult> GetCache<TKey, TResult>();
}

class DefaultCacheManager : ICacheManager
{
    public DefaultCacheManager(Type component, ICacheHolder cacheHolder)
    {
        //do something
    }
    public ICache<TKey, TResult> GetCache<TKey, TResult>()
    {
       //do somthing
    }
}

Autofac代码:

//1.register   
builder.RegisterType<DefaultCacheManager>().As<ICacheManager>().SingleInstance();

//2.reslove  
// the parameter is dynamic 
var parameter = new TypedParameter(do somthing...);    
container.Resolve(parameter);   //resolve by parameter 

问题:

Autofac有一个方法:

object Resolve(Type serviceType, params Parameter[] parameters);

但我不能在干燥处找到params的决心,干how怎么办?

1 个答案:

答案 0 :(得分:1)

简短回答:

container.Resolve<Func<Type, ICacheManager>>()(my parameter ...);