2
Мне нужно решить DbContext на основе значения owin арендатора. Но в рамках метода OnDisconnected от концентратора HttpContext равен not accessible.SignalR - Инъекция зависимостей мутантных
Мой ступица класс:
public class UserTrackingHub : Hub
{
private readonly UserContext _context;
public UserTrackingHub(UserContext context) { ... }
public override async Task OnConnected() { /* OK HERE...*/ }
public override async Task OnDisconnected(bool stopCalled)
{
// NEVER FIRES WITH IF I USE THE CTOR INJECTION.
var connection = await _context.Connections.FindAsync(Context.ConnectionId);
if (connection != null)
{
_context.Connections.Remove(connection);
await _context.SaveChangesAsync();
}
}
}
Вот мой Autofac конфигурации:
public static IContainer Register(IAppBuilder app)
{
var builder = new ContainerBuilder();
// Other registers...
builder.Register<UserContext>(c =>
{
// Details and conditions omitted for brevity.
var context = HttpContext.Current; // NULL in OnDisconnected pipeline.
var owinContext = context.GetOwinContext();
var tenant = owinContext.Environment["app.tenant"].ToString();
var connection = GetConnectionString(tenant);
return new UserContext(connection);
});
var container = builder.Build();
var config = new HubConfiguration
{
Resolver = new AutofacDependencyResolver(container)
};
app.MapSignalR(config);
return container;
}
Может кто-то помочь мне определить арендатора OnDisconnected в той или любым другим способом?
Спасибо!
ли вы когда-нибудь найти решение? Опираясь на эту же проблему. –
@ Jason.Net, я опубликовал решение, которое сработало здесь. Надеюсь, это поможет! –