protected override IServiceProvider CreateServiceProvider(IServiceCollection serviceCollection)
        {
            serviceCollection.AddSingleton <IAspectConfigure, NonIgnoreAspectConfiguration>();
            var aspectCoreServiceProviderFactory = new AspectCoreServiceProviderFactory();

            return(aspectCoreServiceProviderFactory.CreateServiceProvider(serviceCollection));
        }
Example #2
0
        public void CreateBuilderWithAspectCoreServices_Test(Type serviceType)
        {
            var services = new ServiceCollection();
            var aspectCoreServiceProviderFactory = new AspectCoreServiceProviderFactory();
            var proxyServices = aspectCoreServiceProviderFactory.CreateBuilder(services);
            var descriptor    = Assert.Single(proxyServices, d => d.ServiceType == serviceType);

            Assert.False(descriptor.ImplementationType.GetTypeInfo().IsDynamically());
        }
Example #3
0
        public void ServiceProvider_GetService_WithInterceptor_Tests()
        {
            var services = new ServiceCollection();

            services.AddTransient <IService, Service>();
            var aspectCoreServiceProviderFactory = new AspectCoreServiceProviderFactory();
            var proxyServiceProvider             = aspectCoreServiceProviderFactory.CreateServiceProvider(services);
            var proxyService = proxyServiceProvider.GetService <IService>();

            Assert.Equal(proxyService.Get(1), proxyService.Get(1));
        }
Example #4
0
        public void ServiceProvider_GetService_IsDynamically_Tests()
        {
            var services = new ServiceCollection();

            services.AddTransient <IService, Service>();
            var aspectCoreServiceProviderFactory = new AspectCoreServiceProviderFactory();
            var proxyServiceProvider             = aspectCoreServiceProviderFactory.CreateServiceProvider(services);
            var proxyService = proxyServiceProvider.GetService <IService>();

            Assert.True(proxyService.GetType().GetTypeInfo().IsDynamically());
        }
        public void AddAspectConfiguration_Test()
        {
            var services = new ServiceCollection();

            services.AddAspectConfigure(c => { });
            var aspectCoreServiceProviderFactory = new AspectCoreServiceProviderFactory();
            var proxyServices = aspectCoreServiceProviderFactory.CreateBuilder(services);
            var descriptor    = Assert.Single(proxyServices, d => d.ServiceType == typeof(IAspectConfigure));

            Assert.Null(descriptor.ImplementationType);
            Assert.NotNull(descriptor.ImplementationInstance);
        }
Example #6
0
        public void SupportOriginalService_Test()
        {
            var services = new ServiceCollection();

            services.AddTransient <IService, Service>();
            var aspectCoreServiceProviderFactory = new AspectCoreServiceProviderFactory();
            var proxyServiceProvider             = aspectCoreServiceProviderFactory.CreateServiceProvider(services);
            var originalServiceProvider          = proxyServiceProvider.GetService <IOriginalServiceProvider>();
            var service = originalServiceProvider.GetService <IService>();

            Assert.False(service.GetType().GetTypeInfo().IsDynamically());
            Assert.NotEqual(service.Get(1), service.Get(1));
        }
Example #7
0
        public void CreateBuilderWithProxy_Test()
        {
            var services = new ServiceCollection();

            services.AddTransient <IService, Service>();
            var aspectCoreServiceProviderFactory = new AspectCoreServiceProviderFactory();
            var proxyServices = aspectCoreServiceProviderFactory.CreateBuilder(services);
            var descriptor    = Assert.Single(proxyServices, d => d.ServiceType == typeof(IService));

            Assert.NotNull(descriptor.ImplementationType);
            Assert.Equal(descriptor.Lifetime, ServiceLifetime.Transient);
            Assert.IsNotType <Service>(descriptor.ImplementationType);
            Assert.True(descriptor.ImplementationType.GetTypeInfo().IsDynamically());
        }
Example #8
0
        public void ServiceProvider_GetService_WithParameter_Tests()
        {
            var services = new ServiceCollection();

            services.AddTransient <IService, Service>();
            services.AddTransient <IController, Controller>();

            var aspectCoreServiceProviderFactory = new AspectCoreServiceProviderFactory();
            var proxyServiceProvider             = aspectCoreServiceProviderFactory.CreateServiceProvider(services);
            var proxyService = proxyServiceProvider.GetService <IService>();

            Assert.True(proxyService.GetType().GetTypeInfo().IsDynamically());
            Assert.Equal(proxyService.Get(1), proxyService.Get(1));

            var proxyController = proxyServiceProvider.GetService <IController>();

            Assert.Equal(proxyService.Get(100), proxyController.Execute());
        }
        public void Scoped_Test()
        {
            var services = new ServiceCollection();

            services.AddScoped <IService, Service>();
            var aspectCoreServiceProviderFactory = new AspectCoreServiceProviderFactory();
            var proxyServiceProvider             = aspectCoreServiceProviderFactory.CreateServiceProvider(services);
            var service = proxyServiceProvider.GetRequiredService <IService>();

            using (var serviceScope = proxyServiceProvider.GetRequiredService <IServiceScopeFactory>().CreateScope())
            {
                var socpedProvider = serviceScope.ServiceProvider;
                var service1       = socpedProvider.GetRequiredService <IService>();
                var service2       = socpedProvider.GetRequiredService <IService>();
                Assert.Equal(service1, service2);
                Assert.NotEqual(service, service1);
                Assert.NotEqual(service, service2);
            }
        }
Example #10
0
        public void SupportOriginalServiceWithParameter_Test()
        {
            var services = new ServiceCollection();

            services.AddTransient <IService, Service>();
            services.AddTransient <IController, Controller>();
            var aspectCoreServiceProviderFactory = new AspectCoreServiceProviderFactory();
            var proxyServiceProvider             = aspectCoreServiceProviderFactory.CreateServiceProvider(services);
            var originalServiceProvider          = proxyServiceProvider.GetService <IOriginalServiceProvider>();

            var proxyService = originalServiceProvider.GetService <IService>();

            Assert.False(proxyService.GetType().GetTypeInfo().IsDynamically());

            var proxyController = originalServiceProvider.GetService <IController>();

            Assert.False(proxyController.GetType().GetTypeInfo().IsDynamically());
            Assert.False(proxyController.Service.GetType().GetTypeInfo().IsDynamically());

            Assert.NotEqual(proxyService.Get(100), proxyController.Execute());
        }