public FakeOuterService(
     IFakeService singleService,
     IEnumerable<IFakeMultipleService> multipleServices)
 {
     _singleService = singleService;
     _multipleServices = multipleServices;
 }
 public TypeWithSupersetConstructors(
     IFakeMultipleService multipleService,
     IFactoryService factoryService,
     IFakeService fakeService,
     IFakeScopedService scopedService)
 {
 }
 public TypeWithSupersetConstructors(
    IFakeMultipleService multipleService, 
    IFactoryService factoryService,
    IFakeService fakeService,
    IFakeScopedService scopedService)
 {
 }
Example #4
0
 public FakeOuterService(
     IFakeService singleService,
     IEnumerable <IFakeMultipleService> multipleServices)
 {
     SingleService    = singleService;
     MultipleServices = multipleServices;
 }
Example #5
0
 public CacherModel(
     ICache <IMemory> cache,
     IFakeService fakeService)
 {
     _cache       = cache;
     _fakeService = fakeService;
 }
        public ClassWithAmbiguousCtors(IFakeService service, string data1, int data2)
        {
            FakeService = service;
            Data1       = data1;
            Data2       = data2;

            CtorUsed = "IFakeService, string, string";
        }
 public FakeDisposableCallbackOuterService(
     IFakeService singleService,
     IEnumerable <IFakeMultipleService> multipleServices,
     FakeDisposeCallback callback) : base(callback)
 {
     SingleService    = singleService;
     MultipleServices = multipleServices;
 }
 public TypeWithSupersetConstructors(
     IFakeService fakeService,
     IFactoryService factoryService)
     : this(
         fakeService,
         multipleService : null,
         factoryService : factoryService)
 {
 }
 public TypeWithSupersetConstructors(
     IFakeService fakeService,
     IFactoryService factoryService)
     : this(
         fakeService,
         multipleService: null,
         factoryService: factoryService)
 {
 }
 public TypeWithSupersetConstructors(
     IFakeService fakeService,
     IFakeMultipleService multipleService,
     IFactoryService factoryService)
     : this(
         multipleService,
         factoryService,
         fakeService,
         scopedService : null)
 {
 }
 public TypeWithSupersetConstructors(
    IFakeService fakeService,
    IFakeMultipleService multipleService,
    IFactoryService factoryService)
     : this(
         multipleService,
         factoryService,
         fakeService,
         scopedService: null)
 {
 }
Example #12
0
 public static int StaticMethod(
     string message,
     int number,
     IFakeService fakeService,
     IAnotherFakeService anotherFakeService
     )
 {
     ReceivedStaticParams.Add(message);
     ReceivedStaticParams.Add(number);
     ReceivedStaticParams.Add(fakeService);
     ReceivedStaticParams.Add(anotherFakeService);
     return(number);
 }
Example #13
0
 public int InstanceMethod(
     string message,
     int number,
     IFakeService fakeService,
     IAnotherFakeService anotherFakeService
     )
 {
     ReceivedInstanceParams.Add(message);
     ReceivedInstanceParams.Add(number);
     ReceivedInstanceParams.Add(fakeService);
     ReceivedInstanceParams.Add(anotherFakeService);
     return(number);
 }
 public ClassWithServiceAndOptionalArgsCtorWithStructs(IFakeService fake,
                                                       DateTime dateTime                    = new DateTime(),
                                                       DateTime dateTimeDefault             = default(DateTime),
                                                       TimeSpan timeSpan                    = new TimeSpan(),
                                                       TimeSpan timeSpanDefault             = default(TimeSpan),
                                                       DateTimeOffset dateTimeOffset        = new DateTimeOffset(),
                                                       DateTimeOffset dateTimeOffsetDefault = default(DateTimeOffset),
                                                       Guid guid                        = new Guid(),
                                                       Guid guidDefault                 = default(Guid),
                                                       CustomStruct customStruct        = new CustomStruct(),
                                                       CustomStruct customStructDefault = default(CustomStruct)
                                                       )
 {
 }
        public void FactoryServicesAreCreatedAsPartOfCreatingObjectGraph_2()
        {
            var services = new ServiceCollection();

            services.AddTransient <IFakeService, FakeService>();
            services.AddTransient <IFactoryService>((Func <IServiceProvider, IFactoryService>)(p =>
            {
                IFakeService service = p.GetService <IFakeService>();
                return((IFactoryService) new TransientFactoryService()
                {
                    FakeService = service,
                    Value = 42
                });
            }));
            services.AddScoped <ScopedFactoryService>((Func <IServiceProvider, ScopedFactoryService>)(p =>
            {
                IFakeService service = p.GetService <IFakeService>();
                return(new ScopedFactoryService()
                {
                    FakeService = service
                });
            }));
            services.AddTransient <ServiceAcceptingFactoryService>();
            IServiceProvider serviceProvider = this.CreateServiceProvider((IServiceCollection)services);

            using (var scope = serviceProvider.CreateScope())
            {
                serviceProvider = scope.ServiceProvider;

                ServiceAcceptingFactoryService service1 = serviceProvider.GetService <ServiceAcceptingFactoryService>();
                ServiceAcceptingFactoryService service2 = serviceProvider.GetService <ServiceAcceptingFactoryService>();
                Assert.Equal <int>(42, service1.TransientService.Value);
                Assert.NotNull((object)service1.TransientService.FakeService);
                Assert.Equal <int>(42, service2.TransientService.Value);
                Assert.NotNull((object)service2.TransientService.FakeService);
                Assert.NotNull((object)service1.ScopedService.FakeService);
                Assert.NotSame((object)service1.TransientService, (object)service2.TransientService);
                Assert.Same((object)service1.ScopedService, (object)service2.ScopedService);
            }
        }
Example #16
0
        public void NonSingletonService_WithInjectedProvider_ResolvesScopeProvider(ServiceLifetime lifetime)
        {
            // Arrange
            var collection = new TestServiceCollection();

            collection.AddScoped <IFakeService, FakeService>();
            collection.Add(new ServiceDescriptor(typeof(ClassWithServiceProvider), typeof(ClassWithServiceProvider), lifetime));
            var provider = CreateServiceProvider(collection);

            // Act
            IFakeService fakeServiceFromScope1      = null;
            IFakeService otherFakeServiceFromScope1 = null;
            IFakeService fakeServiceFromScope2      = null;
            IFakeService otherFakeServiceFromScope2 = null;

            using (var scope1 = provider.CreateScope())
            {
                var serviceWithProvider = scope1.ServiceProvider.GetRequiredService <ClassWithServiceProvider>();
                fakeServiceFromScope1 = serviceWithProvider.ServiceProvider.GetRequiredService <IFakeService>();

                serviceWithProvider        = scope1.ServiceProvider.GetRequiredService <ClassWithServiceProvider>();
                otherFakeServiceFromScope1 = serviceWithProvider.ServiceProvider.GetRequiredService <IFakeService>();
            }

            using (var scope2 = provider.CreateScope())
            {
                var serviceWithProvider = scope2.ServiceProvider.GetRequiredService <ClassWithServiceProvider>();
                fakeServiceFromScope2 = serviceWithProvider.ServiceProvider.GetRequiredService <IFakeService>();

                serviceWithProvider        = scope2.ServiceProvider.GetRequiredService <ClassWithServiceProvider>();
                otherFakeServiceFromScope2 = serviceWithProvider.ServiceProvider.GetRequiredService <IFakeService>();
            }

            // Assert
            Assert.Same(fakeServiceFromScope1, otherFakeServiceFromScope1);
            Assert.Same(fakeServiceFromScope2, otherFakeServiceFromScope2);
            Assert.NotSame(fakeServiceFromScope1, fakeServiceFromScope2);
        }
Example #17
0
 public ClassWithAmbiguousCtors(IFakeService service, string data)
 {
 }
Example #18
0
 public OtherTask(IFakeService fakeService)
 {
     _fakeService = fakeService;
 }
 public OkFeature(IFakeService fakeService)
 {
     _fakeService = fakeService;
 }
 public TypeWithSupersetConstructors(
     IFakeService fakeService, 
     IFactoryService factoryService)
 {
 }
 public FirstMessageConsumer(IFakeService fakeService)
 {
     _fakeService = fakeService;
 }
 public AnotherClassAcceptingData(IFakeService fakeService, string one, string two)
 {
     _fakeService = fakeService;
     _one = one;
     _two = two;
 }
 public ActionWithBodyFeatureWithException(IFakeService fakeService)
 {
     _fakeService = fakeService;
 }
 public TypeWithGenericServices(
     IFakeService fakeService,
     IFactoryService factoryService,
     IFakeOpenGenericService<IFakeService> logger)
 {
 }
 public TypeWithGenericServices(
    IFakeMultipleService multipleService,
    IFakeService fakeService)
 {
 }
 public TypeWithNonOverlappedConstructors(
     IFakeScopedService scopedService,
     IFakeService fakeService,
     IFakeMultipleService multipleService)
 {
 }
 public AnotherClass(IFakeService fakeService)
 {
     _fakeService = fakeService;
 }
 public FakeController(IFakeService fakeService)
 {
     FakeService = fakeService;
 }
 public TypeWithMultipleParameterizedConstructors(IFakeService fakeService)
 {
 }
 public TypeWithSupersetConstructors(IFakeService fakeService)
     : this(
         fakeService,
         factoryService : null)
 {
 }
Example #31
0
 public OtherTask(IFakeService fakeService)
 {
     _fakeService = fakeService;
 }
Example #32
0
 public ActionFeature(IFakeService fakeService)
 {
     _fakeService = fakeService;
 }
Example #33
0
 public ExampleTask(IFakeService fakeService)
 {
     _fakeService = fakeService;
 }
 public TypeWithDefaultConstructorParameters(
     IFakeMultipleService multipleService,
     IFakeService fakeService = null)
 {
 }
 public DependOnNonexistentService(IFakeService nonExistentService)
 {
 }
Example #36
0
 public TypeWithMultipleParameterizedConstructors(IFakeService fakeService)
 {
 }
 public TypeWithUnresolvableEnumerableConstructors(IFakeService fakeService)
 {
 }
 public OkFeatureWithException(IFakeService fakeService)
 {
     _fakeService = fakeService;
 }
Example #39
0
 public CreationCountFakeService(IFakeService dependency)
 {
     InstanceCount++;
     InstanceId = InstanceCount;
 }
Example #40
0
 public ExampleTask(IFakeService fakeService)
 {
     _fakeService = fakeService;
 }
Example #41
0
 public ClassWithAmbiguousCtors(IFakeService service, string data1, int data2)
 {
     FakeService = service;
     Data1 = data1;
     Data2 = data2;
 }
Example #42
0
 public ClassWithAmbiguousCtors(IFakeService service, int data)
 {
 }
 public ClassWithThrowingCtor(IFakeService service)
 {
     throw new Exception(nameof(ClassWithThrowingCtor));
 }
Example #44
0
 public AnotherClassAcceptingData(IFakeService fakeService, string one, string two)
 {
     FakeService = fakeService;
     One         = one;
     Two         = two;
 }
 public CreationCountFakeService(IFakeService dependency)
 {
     _instanceCount++;
     _instanceId = _instanceCount;
 }
Example #46
0
 public TypeWithDefaultConstructorParameters(
     IFakeMultipleService multipleService,
     IFakeService fakeService = null)
 {
 }
 public TypeWithUnresolvableEnumerableConstructors(IFakeService fakeService)
 {
 }
 public ActionWithBodyFeature(IFakeService fakeService)
 {
     _fakeService = fakeService;
 }
Example #49
0
 public ClassWithThrowingCtor(IFakeService service)
 {
     throw new Exception(nameof(ClassWithThrowingCtor));
 }
 public CreationCountFakeService(IFakeService dependency)
 {
     InstanceCount++;
     InstanceId = InstanceCount;
 }
Example #51
0
 public ClassWithAmbiguousCtorsAndAttribute(IFakeService service, IFakeOuterService service2, string data)
 {
     CtorUsed = "IFakeService, IFakeService, string";
 }
 public TypeWithSupersetConstructors(IFakeService fakeService)
     : this(
         fakeService,
         factoryService: null)
 {
 }
 public TypeWithParameterizedConstructor(IFakeService fakeService)
 {
 }
Example #54
0
 public ClassWithMultipleMarkedCtors(IFakeService service, string data)
 {
 }
 public TypeWithParameterizedAndNullaryConstructor(IFakeService fakeService)
 {
 }