示例#1
0
        protected override Type?VisitIEnumerable(IEnumerableCallSite enumerableCallSite,
                                                 CallSiteValidatorState state)
        {
            Type?result = null;

            foreach (ServiceCallSite serviceCallSite in enumerableCallSite.ServiceCallSites)
            {
                Type?scoped = VisitCallSite(serviceCallSite, state);
                result ??= scoped;
            }
            return(result);
        }
 protected override Type VisitScoped(ScopedCallSite scopedCallSite, CallSiteValidatorState state)
 {
     // We are fine with having ServiceScopeService requested by singletons
     if (scopedCallSite.ServiceCallSite is ServiceScopeService)
     {
         return(null);
     }
     if (state.Singleton != null)
     {
         throw new InvalidOperationException(nameof(state.Singleton) + "范围调用点不能为单例调用点。");
     }
     return(scopedCallSite.Key.ServiceType);
 }
示例#3
0
        protected override Type VisitIEnumerable(IEnumerableCallSite enumerableCallSite,
                                                 CallSiteValidatorState state)
        {
            Type result = null;

            foreach (var serviceCallSite in enumerableCallSite.ServiceCallSites)
            {
                var scoped = VisitCallSite(serviceCallSite, state);
                if (result == null)
                {
                    result = scoped;
                }
            }
            return(result);
        }
 protected override Type VisitScoped(ScopedCallSite scopedCallSite, CallSiteValidatorState state)
 {
     // We are fine with having ServiceScopeService requested by singletons
     if (scopedCallSite.ServiceCallSite is ServiceScopeService)
     {
         return(null);
     }
     if (state.Singleton != null)
     {
         throw new InvalidOperationException(Resources.FormatScopedInSingletonException(
                                                 scopedCallSite.Key.ServiceType,
                                                 state.Singleton.Key.ServiceType,
                                                 nameof(ServiceLifetime.Scoped).ToLowerInvariant(),
                                                 nameof(ServiceLifetime.Singleton).ToLowerInvariant()
                                                 ));
     }
     return(scopedCallSite.Key.ServiceType);
 }
示例#5
0
        protected override Type VisitScopeCache(ServiceCallSite scopedCallSite, CallSiteValidatorState state)
        {
            // We are fine with having ServiceScopeService requested by singletons
            if (scopedCallSite.ServiceType == typeof(IServiceScopeFactory))
            {
                return(null);
            }
            if (state.Singleton != null)
            {
                throw new InvalidOperationException(SR.Format(SR.ScopedInSingletonException,
                                                              scopedCallSite.ServiceType,
                                                              state.Singleton.ServiceType,
                                                              nameof(ServiceLifetime.Scoped).ToLowerInvariant(),
                                                              nameof(ServiceLifetime.Singleton).ToLowerInvariant()
                                                              ));
            }

            VisitCallSiteMain(scopedCallSite, state);
            return(scopedCallSite.ServiceType);
        }
示例#6
0
        protected override Type VisitScopeCache(ServiceCallSite scopedCallSite, CallSiteValidatorState state)
        {
            // We are fine with having ServiceScopeService requested by singletons
            if (scopedCallSite is ServiceScopeFactoryCallSite)
            {
                return(null);
            }

            if (state.Singleton != null)
            {
                throw new InvalidOperationException(string.Format("Cannot consume {2} service '{0}' from {3} '{1}'.",
                                                                  scopedCallSite.ServiceType,
                                                                  state.Singleton.ServiceType,
                                                                  nameof(ServiceLifetime.Scoped).ToLowerInvariant(),
                                                                  nameof(ServiceLifetime.Singleton).ToLowerInvariant()
                                                                  ));
            }

            VisitCallSiteMain(scopedCallSite, state);

            return(scopedCallSite.ServiceType);
        }
示例#7
0
 protected override Type VisitServiceScopeFactory(ServiceScopeFactoryCallSite serviceScopeFactoryCallSite, CallSiteValidatorState state) => null;
示例#8
0
 protected override Type VisitServiceProvider(ServiceProviderCallSite serviceProviderCallSite, CallSiteValidatorState state) => null;
示例#9
0
 protected override Type VisitConstant(ConstantCallSite constantCallSite, CallSiteValidatorState state) => null;
 protected override Type VisitSingleton(SingletonCallSite singletonCallSite, CallSiteValidatorState state)
 {
     state.Singleton = singletonCallSite;
     return(VisitCallSite(singletonCallSite.ServiceCallSite, state));
 }
示例#11
0
 protected override Type VisitInterception(InterceptionCallSite interceptionCallSite, CallSiteValidatorState argument) => null;
 protected override Type VisitFactoryService(FactoryService factoryService, CallSiteValidatorState state) => null;
 protected override Type VisitEmptyIEnumerable(EmptyIEnumerableCallSite emptyIEnumerableCallSite, CallSiteValidatorState state) => null;
 protected override Type VisitInstanceService(InstanceService instanceCallSite, CallSiteValidatorState state) => null;
示例#15
0
        protected override Type?VisitConstructor(ConstructorCallSite constructorCallSite, CallSiteValidatorState state)
        {
            Type?result = null;

            foreach (ServiceCallSite parameterCallSite in constructorCallSite.ParameterCallSites)
            {
                Type?scoped = VisitCallSite(parameterCallSite, state);
                result ??= scoped;
            }
            return(result);
        }
示例#16
0
 protected override Type VisitFactory(FactoryCallSite factoryCallSite, CallSiteValidatorState state) => null;
示例#17
0
        protected override Type VisitConstructor(ConstructorCallSite constructorCallSite, CallSiteValidatorState state)
        {
            Type result = null;

            foreach (var parameterCallSite in constructorCallSite.ParameterCallSites)
            {
                var scoped = VisitCallSite(parameterCallSite, state);
                if (result == null)
                {
                    result = scoped;
                }
            }
            return(result);
        }
 protected override Type VisitCreateInstance(CreateInstanceCallSite createInstanceCallSite, CallSiteValidatorState state) => null;
示例#19
0
 protected override Type VisitRootCache(ServiceCallSite singletonCallSite, CallSiteValidatorState state)
 {
     state.Singleton = singletonCallSite;
     return(VisitCallSiteMain(singletonCallSite, state));
 }
 protected override Type VisitTransient(TransientCallSite transientCallSite, CallSiteValidatorState state)
 {
     return(VisitCallSite(transientCallSite.ServiceCallSite, state));
 }