using Origami.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autofac;
namespace OrigamiService.Dependency_Injection
{
public class AutofacDependencyResolver : IResolver
{
private readonly IContainer _serviceProvider;
public ServiceProviderDependencyResolver(IContainer serviceProvider)
{
_serviceProvider = serviceProvider;
}
public T GetService<T>() => _serviceProvider.Resolve<T>();
public object GetService(Type serviceType) => _serviceProvider.Resolve(serviceType);
public T GetRequiredService<T>() => GetScopedServiceProvider().GetRequiredService<T>();
public object GetRequiredService(Type type) => GetScopedServiceProvider().GetRequiredService(type);
public IEnumerable<T> GetServices<T>() => _serviceProvider.re;
public IEnumerable<object> GetServices(Type serviceType) => GetScopedServiceProvider().GetServices(serviceType);
public IEnumerable<T> GetRequiredServices<T>() => GetScopedServiceProvider().GetServices<T>();
public IEnumerable<object> GetRequiredServices(Type type) => GetScopedServiceProvider().GetServices(type);
private IContainer GetScopedServiceProvider()
{
var scope = _serviceProvider.
return scope.ServiceProvider;
}
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter