Skip to content

Commit

Permalink
renaming things
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed May 3, 2021
1 parent 86e30ab commit e0bb6c5
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/DryIoc.AzureFunctions/DryIocAzureFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public static IFunctionsHostBuilder UseDryIoc(this IFunctionsHostBuilder hostBui
});

// Funny, but we can actually Replace the Azure Functions ServiceProvider
hostBuilder.Services.Replace(ServiceDescriptor.Singleton(typeof(IJobActivator), typeof(ScopedJobActivator)));
hostBuilder.Services.Replace(ServiceDescriptor.Singleton(typeof(IJobActivatorEx), typeof(ScopedJobActivator)));
hostBuilder.Services.Replace(ServiceDescriptor.Singleton(typeof(IJobActivator), typeof(DryIocJobActivator)));
hostBuilder.Services.Replace(ServiceDescriptor.Singleton(typeof(IJobActivatorEx), typeof(DryIocJobActivator)));

hostBuilder.Services.AddScoped<ScopedResolverContext>();
hostBuilder.Services.AddScoped<DryIocScopedResolverContext>();

return hostBuilder;
}
Expand All @@ -80,27 +80,27 @@ public sealed class FunctionName
internal FunctionName(string name) => Name = name;
}

internal sealed class ScopedResolverContext : IDisposable
internal sealed class DryIocScopedResolverContext : IDisposable
{
public readonly IResolverContext Scope;
public ScopedResolverContext(IContainer container) =>
public DryIocScopedResolverContext(IContainer container) =>
Scope = container.OpenScope(); // todo: @clarify do we need the named scope here?
public void Dispose() => Scope.Dispose();
}

internal sealed class ScopedJobActivator : IJobActivator, IJobActivatorEx
internal sealed class DryIocJobActivator : IJobActivator, IJobActivatorEx
{
private readonly IServiceProvider _serviceProvider;
public ScopedJobActivator(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;
public DryIocJobActivator(IServiceProvider serviceProvider) => _serviceProvider = serviceProvider;

public T CreateInstance<T>() =>
_serviceProvider.GetRequiredService<ScopedResolverContext>().Scope.Resolve<T>();
_serviceProvider.GetRequiredService<DryIocScopedResolverContext>().Scope.Resolve<T>();

public T CreateInstance<T>(IFunctionInstanceEx functionInstance)
{
var functionServices = functionInstance.InstanceServices;
var scope = (functionServices.GetService<ScopedResolverContext>()
?? _serviceProvider.GetRequiredService<ScopedResolverContext>()).Scope;
var scope = (functionServices.GetService<DryIocScopedResolverContext>()
?? _serviceProvider.GetRequiredService<DryIocScopedResolverContext>()).Scope;

var loggerFactory = functionServices.GetService<ILoggerFactory>();
if (loggerFactory != null)
Expand Down

0 comments on commit e0bb6c5

Please sign in to comment.