public override void AddType(IServiceCollection services, Type type)
        {
            if (IsConventionalRegistrationDisabled(type))
            {
                return;
            }

            if (!IsHub(type))
            {
                return;
            }

            var serviceTypes = ExposedServiceExplorer.GetExposedServices(type);

            TriggerServiceExposing(services, type, serviceTypes);

            foreach (var serviceType in serviceTypes)
            {
                services.Add(
                    ServiceDescriptor.Describe(
                        serviceType,
                        type,
                        ServiceLifetime.Transient
                        )
                    );
            }
        }
示例#2
0
        private static void AddType(IServiceCollection services, Type type)
        {
            var serviceAttribute = type.GetCustomAttribute <ServiceAttribute>(true);

            if (serviceAttribute == null)
            {
                return;
            }

            var lifeTime = serviceAttribute.Lifetime;

            var serviceTypes = ExposedServiceExplorer.GetExposedServices(type);

            foreach (var serviceType in serviceTypes)
            {
                var serviceDescriptor = ServiceDescriptor.Describe(serviceType, type, lifeTime);

                if (serviceAttribute?.ReplaceServices == true)
                {
                    services.Replace(serviceDescriptor);
                }
                else if (serviceAttribute?.TryRegister == true)
                {
                    services.TryAdd(serviceDescriptor);
                }
                else
                {
                    services.Add(serviceDescriptor);
                }
            }
        }
示例#3
0
    public void Should_Get_Custom_Exposed_Types_If_Available()
    {
        //Act

        var exposedServices = ExposedServiceExplorer.GetExposedServices(typeof(ExplicitDerivedService));

        //Assert

        exposedServices.Count.ShouldBe(1);
        exposedServices.ShouldContain(typeof(IDerivedService));
    }
示例#4
0
    public void Should_Get_Conventional_Exposed_Generic_Types_By_Default()
    {
        //Act
        var exposedServices = ExposedServiceExplorer.GetExposedServices(typeof(DefaultGenericService));

        //Assert
        exposedServices.Count.ShouldBe(4);
        exposedServices.ShouldContain(typeof(IService));
        exposedServices.ShouldContain(typeof(IGenericService <string>));
        exposedServices.ShouldContain(typeof(IGenericService <int>));
        exposedServices.ShouldContain(typeof(DefaultGenericService));
    }
示例#5
0
    public void Should_Get_Conventional_Exposed_Types_By_Default()
    {
        //Act

        var exposedServices = ExposedServiceExplorer.GetExposedServices(typeof(DefaultDerivedService));

        //Assert

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

            if (!IsMvcService(type))
            {
                return;
            }

            var lifeTime = GetMvcServiceLifetime(type);

            var serviceTypes = ExposedServiceExplorer.GetExposedServices(type);

            TriggerServiceExposing(services, type, serviceTypes);

            foreach (var serviceType in serviceTypes)
            {
                var serviceDescriptor = ServiceDescriptor.Describe(serviceType, type, lifeTime);
                services.Add(serviceDescriptor);
            }
        }
示例#7
0
 protected virtual List <Type> GetExposedServiceTypes(Type type)
 {
     return(ExposedServiceExplorer.GetExposedServices(type));
 }