AutoFac - SingleInstance per dependency

Viewed 531

Is it possible with AutoFac to have a SingleInstancePerCondition(). I have two websites who run on a single IIS website and I would like to have 2 instances of my interface.

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
{
}
1 Answers
Related