fix injectionses
This commit is contained in:
parent
b93115d787
commit
cd078ca643
11 changed files with 119 additions and 55 deletions
|
@ -2,7 +2,10 @@ namespace Femto.Common;
|
|||
|
||||
public interface ICurrentUserContext
|
||||
{
|
||||
CurrentUser? CurrentUser { get; }
|
||||
CurrentUser? tryGetUserCurrentUser();
|
||||
|
||||
bool HasUser { get; }
|
||||
CurrentUser CurrentUser { get; }
|
||||
}
|
||||
|
||||
public record CurrentUser(Guid Id, string Username, string SessionId);
|
||||
|
|
21
Femto.Common/ScopeBinding.cs
Normal file
21
Femto.Common/ScopeBinding.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Femto.Common;
|
||||
|
||||
/// <summary>
|
||||
/// We use this to bind a scope to the request scope in the composition root
|
||||
/// Any scoped services provided by this subcontainer should be accessed via a ScopeBinding injected in the host
|
||||
/// </summary>
|
||||
/// <param name="scope"></param>
|
||||
public class ScopeBinding<T>(IServiceScope scope) : IDisposable
|
||||
where T : notnull
|
||||
{
|
||||
public T GetService() {
|
||||
return scope.ServiceProvider.GetRequiredService<T>();
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
scope.Dispose();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue