Пример #1
0
        private static object CreateProxy(
            this IServiceProvider serviceProvider,
            Type interfaceType,
            Func <IServiceProvider, object> implementationFactory)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }
            if (interfaceType == null)
            {
                throw new ArgumentNullException(nameof(interfaceType));
            }
            if (implementationFactory == null)
            {
                throw new ArgumentNullException(nameof(implementationFactory));
            }
            interfaceType.ThrowIfNotInterface();

            object  service            = implementationFactory(serviceProvider);
            Type    implementationType = service.GetType();
            ILogger logger             = serviceProvider.GetRequiredService <ILogger>().ForContext(implementationType);

            return(LogProxy.Create(interfaceType, service, logger, s_DefaultLogTypes));
        }
Пример #2
0
        private static TService CreateProxy <TService, TImplementation>(this IServiceProvider serviceProvider)
            where TService : class
            where TImplementation : class, TService
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }
            typeof(TService).ThrowIfNotInterface();

            TImplementation service = serviceProvider.GetRequiredService <TImplementation>();
            ILogger         logger  = serviceProvider.GetRequiredService <ILogger>().ForContext <TImplementation>();

            return(LogProxy.Create <TService>(service, logger, s_DefaultLogTypes));
        }