1
AutoFac有可能擁有SingleInstancePerCondition()
。 我有兩個網站在單個IIS網站上運行,我想要有2個我的界面實例。AutoFac - 每個依賴項的單一實例
protected void Setup(ContainerBuilder builder)
{
builder.Register(CreateBackofficeUserService)
.As<IBackofficeUserService>()
.SingleInstance()
}
private static IBackofficeUserService CreateBackofficeUserService(IComponentContext context)
{
var siteName = Context.GetSiteName();
if (siteName == "SiteA")
return new SiteABackofficeUserService();
else if (siteName == "SiteB")
return new SiteBBackofficeUserService();
else
return null;
}
public interface IBackofficeUserService
{
}
public class SiteABackofficeUserService : IBackofficeUserService
{
}
public class SiteBBackofficeUserService : IBackofficeUserService
{
}
謝謝你,難道還要注入那些nammed參數代入我的控制器的構造函數的參數? – user2003035