Пример #1
0
        public Expression GetExpression(
            IResolutionStrategy resolutionStrategy,
            TypeInformation typeInfo,
            ResolutionContext resolutionContext)
        {
            var name         = typeInfo.DependencyName;
            var configurator = name != null
                ? context =>
            {
                context.WithName(name);
                resolutionContext.RequestInitiatorContainerContext.ContainerConfiguration.UnknownTypeConfigurator?.Invoke(context);
            }
            : resolutionContext.RequestInitiatorContainerContext.ContainerConfiguration.UnknownTypeConfigurator;

            var registrationConfigurator = new UnknownRegistrationConfigurator(typeInfo.Type, typeInfo.Type);

            configurator?.Invoke(registrationConfigurator);

            if (!registrationConfigurator.TypeMapIsValid(out _))
            {
                return(null);
            }

            var registration = this.registrationBuilder.BuildServiceRegistration(resolutionContext.RequestInitiatorContainerContext,
                                                                                 registrationConfigurator, false);

            this.serviceRegistrator.Register(resolutionContext.RequestInitiatorContainerContext, registration, typeInfo.Type);

            return(resolutionStrategy.BuildExpressionForRegistration(registration, resolutionContext.ShouldFallBackToRequestInitiatorContext
                ? resolutionContext.BeginCrossContainerContext(resolutionContext.RequestInitiatorContainerContext)
                : resolutionContext,
                                                                     typeInfo));
        }
Пример #2
0
        private Expression BuildExpressionByRegistrationType(ServiceRegistration serviceRegistration, ResolutionContext resolutionContext, Type requestedType)
        {
            resolutionContext = resolutionContext.ShouldFallBackToRequestInitiatorContext
                ? resolutionContext.BeginCrossContainerContext(resolutionContext.RequestInitiatorContainerContext)
                : resolutionContext;

            return(serviceRegistration.RegistrationType switch
            {
                RegistrationType.Factory => this.GetExpressionForFactory(serviceRegistration, resolutionContext, requestedType),
                RegistrationType.Instance => serviceRegistration.RegistrationContext.ExistingInstance.AsConstant(),
                RegistrationType.WireUp => this.expressionFactory.ConstructBuildUpExpression(serviceRegistration,
                                                                                             resolutionContext, serviceRegistration.RegistrationContext.ExistingInstance.AsConstant(),
                                                                                             serviceRegistration.ImplementationType),
                RegistrationType.Func => this.GetExpressionForFunc(serviceRegistration, resolutionContext),
                _ => this.GetExpressionForDefault(serviceRegistration, resolutionContext)
            });
Пример #3
0
 public IEnumerable <Expression> GetExpressionsForEnumerableRequest(
     IResolutionStrategy resolutionStrategy,
     TypeInformation typeInfo,
     ResolutionContext resolutionContext) =>
 resolutionStrategy.BuildExpressionsForEnumerableRequest(resolutionContext.BeginCrossContainerContext(resolutionContext
                                                                                                      .CurrentContainerContext.ParentContext), typeInfo);
Пример #4
0
 public Expression GetExpression(
     IResolutionStrategy resolutionStrategy,
     TypeInformation typeInfo,
     ResolutionContext resolutionContext) =>
 resolutionStrategy.BuildExpressionForType(resolutionContext.BeginCrossContainerContext(resolutionContext
                                                                                        .CurrentContainerContext.ParentContext), typeInfo);