Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultHtmlContentReader"/> class.
 /// </summary>
 /// <param name="clientFactory">The clientFactory<see cref="IHttpClientFactory"/>.</param>
 /// <param name="cacheProvider">The cacheProvider<see cref="ICacheProvider"/>.</param>
 /// <param name="proxySelector">The proxySelector<see cref="IProxySelector"/>.</param>
 /// <param name="conf">The aVLibConf<see cref="Configuration"/>.</param>
 public DefaultHtmlContentReader(IHttpClientFactory clientFactory, ICacheProvider cacheProvider, IProxySelector proxySelector, Configuration conf)
 {
     this.cacheProvider = cacheProvider;
     this.proxySelector = proxySelector;
     this.conf          = conf;
     this.clientFactory = clientFactory;
 }
Esempio n. 2
0
 private void SetParameters(object ImplementationObj, IInterceptorContext context, IProxySelector proxySelector, Type serviceType, Type impType)
 {
     this._implementationObj = ImplementationObj;
     this._context           = context;
     this._proxySelector     = proxySelector;
     this._serviceType       = serviceType;
     this._impType           = impType;
 }
        private static void BindInterceptorTypeMap <TInterface>(IServiceCollection services, TypeMap typeMap, ServiceLifetime lifetime)
        {
            var implementationType = typeMap.ImplementationType;

            var serviceTypes = typeMap.ServiceTypes.Where(t => t != typeof(IProxySelector) &&
                                                          t != typeof(IInterceptorContext) &&
                                                          t != typeof(IProxyGenerator) &&
                                                          t != typeof(ISingletonType) &&
                                                          t != typeof(IScopedType) &&
                                                          t != typeof(ITransientType)).ToList();

            foreach (var serviceType in serviceTypes)
            {
                var oldDescription = services.FirstOrDefault(t => t.ServiceType == typeof(TInterface));
                if (oldDescription != null)
                {
                    services.Remove(oldDescription);
                }

                services.Add(new ServiceDescriptor(implementationType, implementationType, lifetime));

                services.AddTransient(serviceType, sp =>
                {
                    IProxySelector proxySelector = sp.GetRequiredService <IProxySelector>();

                    bool isIncludeAspect = proxySelector.ShouldInterceptType(implementationType);

                    if (!implementationType.IsAssignableTo(serviceType))
                    {
                        throw new InvalidOperationException($@"Type ""{implementationType.ToFriendlyName()}"" is not assignable to ""${serviceType.ToFriendlyName()}"".");
                    }

                    object obj = sp.GetRequiredService(implementationType);
                    IProxyGenerator objProxy    = new ProxyGenerator(proxySelector);
                    IInterceptorContext context = new InterceptorContext();
                    return(objProxy.Create(serviceType, implementationType, obj, context));
                });
            }
        }
Esempio n. 4
0
 public ProxyGenerator(IProxySelector proxySelector)
 {
     _proxySelector = proxySelector;
 }