Ejemplo n.º 1
0
        public void Should_Get_Two_ExposedServices()
        {
            var exposedServices = ExposedServiceExplorer.GetExposedServices(typeof(AppServices));

            exposedServices.Count.ShouldBe(2);
            exposedServices.ShouldContain(typeof(AppServices));
            exposedServices.ShouldContain(typeof(IAppServices));
        }
Ejemplo n.º 2
0
        public void Should_Get_Only_One_ExposedServices()
        {
            // Act
            var exposedServices = ExposedServiceExplorer.GetExposedServices(typeof(ExplicitDerivedService));

            // Assert
            exposedServices.Count.ShouldBe(1);
            exposedServices.ShouldContain(typeof(IDerivedService));
        }
Ejemplo n.º 3
0
        public void Should_Get_ExposedServices_By_Conventional()
        {
            var exposedServices = ExposedServiceExplorer.GetExposedServices(typeof(DefaultDerivedService));

            exposedServices.Count.ShouldBe(3);
            exposedServices.ShouldContain(typeof(DefaultDerivedService));
            exposedServices.ShouldContain(typeof(IService));
            exposedServices.ShouldContain(typeof(IDerivedService));
        }
Ejemplo n.º 4
0
        public override void AddType(IServiceCollection services, Type type)
        {
            if (this.IsConventionalRegistrationDisabled(type))
            {
                return;
            }

            var dependencyAttribute = this.GetDependencyAttributeOrNull(type);
            var serviceLifetime     = this.GetServiceLifeTimeOrNull(type, dependencyAttribute);

            if (serviceLifetime == null)
            {
                return;
            }

            var exposedServiceTypes = ExposedServiceExplorer.GetExposedServices(type);

            // TODO 支持过滤暴露的服务

            foreach (Type exposedServiceType in exposedServiceTypes)
            {
                var serviceDescriptor = this.CreateServiceDescriptor(exposedServiceType, type, serviceLifetime.Value);

                if (dependencyAttribute == null)
                {
                    services.Add(serviceDescriptor);
                }
                else
                {
                    switch (dependencyAttribute.RegisterType)
                    {
                    case RegisterType.Normal:
                        services.Add(serviceDescriptor);
                        break;

                    case RegisterType.Replace:
                        services.Replace(serviceDescriptor);
                        break;

                    case RegisterType.TryAdd:
                        services.TryAdd(serviceDescriptor);
                        break;
                    }
                }
            }
        }