Ejemplo n.º 1
0
 public Subject(string argument1, TransientService service1, string argument2, SingletonService service2)
 {
     Argument1 = argument1;
     Service1  = service1;
     Argument2 = argument2;
     Service2  = service2;
 }
Ejemplo n.º 2
0
 public LifeTimeController(TransientService transientService,
                           ScopedService scopedService, SingletonService singletonService)
 {
     _transientService = transientService;
     _scopedService    = scopedService;
     _singletonService = singletonService;
 }
Ejemplo n.º 3
0
 public ValuesController(ScopedService scoped, TransientService transient, SingletonService singleton, ICorrelationContextAccessor accessor)
 {
     _accessor  = accessor;
     _scoped    = scoped;
     _transient = transient;
     _singleton = singleton;
 }
 internal Test1Controller(ILogger <Test1Controller> logger, SingeltonService singletonservice, TransientService transientservice, AppServer appserver)
 {
     _logger           = logger;
     _singletonservice = singletonservice;
     _transientservice = transientservice;
     _appserver        = appserver;
 }
Ejemplo n.º 5
0
        public async Task InvokeAsync(HttpContext context, TransientService transientService, ScopedService scopedService, SingletonService singletonService)
        {
            context.Items.Add("CustomMiddlewareTransient", $"Transient Middleware - {transientService.GetGuid()}");
            context.Items.Add("CustomMiddlewareScoped", $"Scoped Middleware - {scopedService.GetGuid()}");
            context.Items.Add("CustomMiddlewareSingleton", $"Singleton Middleware - {singletonService.GetGuid()}");

            await _next(context);
        }
Ejemplo n.º 6
0
        public void CreateInstance_ExplicitParameters_ReturnsInstance()
        {
            var service = new TransientService();
            var subject = ActivatorUtilities.CreateInstance <Subject>(ServiceProvider, service);

            Assert.NotNull(subject);
            Assert.NotNull(subject.Service);
            Assert.Equal(service, subject.Service);
        }
Ejemplo n.º 7
0
        public void CreateInstance_ExplicitService_UsesCorrectConstructor()
        {
            var service = new TransientService();
            var subject = ActivatorUtilities.CreateInstance <Subject>(ServiceProvider, service);

            Assert.NotNull(subject);
            Assert.Equal(service, subject.TransientService);
            Assert.Null(subject.Argument);
        }
Ejemplo n.º 8
0
 public IlfracombeContext(
     DbContextOptions <IlfracombeContext> options,
     SingletonService singletonService,
     TransientService transientService)
     : base(options)
 {
     SingletonService = singletonService;
     TransientService = transientService;
 }
Ejemplo n.º 9
0
        public async ValueTask InvokeAsync(InvocationContext invocationContext,
                                           SingletonService singletonService1, SingletonService singletonService2,
                                           ScopedService scopedService1, ScopedService scopedService2,
                                           TransientService transientService1, TransientService transientService2)
        {
            Console.WriteLine($"[{GetType().Name}]: Before invoking");
            await invocationContext.ProceedAsync();

            Console.WriteLine($"[{GetType().Name}]: After invoking");
        }
Ejemplo n.º 10
0
 public DependencyTestController(TransientService transientService1,
                                 TransientService transientService2,
                                 ScopedService scopedService1,
                                 ScopedService scopedService2)
 {
     _transientService1 = transientService1;
     _transientService2 = transientService2;
     _scopedService1    = scopedService1;
     _scopedService2    = scopedService2;
 }
Ejemplo n.º 11
0
        public MyJob(
            TransientService transientService,
            // System.InvalidOperationException: Cannot consume scoped service 'Scope.Services.ScopeService' from singleton 'Microsoft.AspNetCore.Hosting.Internal.HostedServiceExecutor'
//            ScopeService scopeService,
            SingletonService singletonService)
        {
            this.transientService = transientService;
//            this.scopeService = scopeService;
            this.singletonService = singletonService;
        }
Ejemplo n.º 12
0
        public void Transient_GetTwice_DifferentInstances()
        {
            IServiceProvider scopedProvider = _provider.CreateScope().ServiceProvider;
            TransientService transient1     = _provider.GetService <TransientService>();
            TransientService transient2     = _provider.GetService <TransientService>();
            TransientService transient3     = scopedProvider.GetService <TransientService>();

            Assert.AreNotEqual(transient1, transient2);
            Assert.AreNotEqual(transient1, transient3);
            Assert.AreNotEqual(transient2, transient3);
        }
Ejemplo n.º 13
0
 public CombeMartinContext(
     DbContextOptions <CombeMartinContext> options,
     SingletonService singletonService,
     ScopedService scopedService,
     TransientService transientService)
     : base(options)
 {
     SingletonService = singletonService;
     ScopedService    = scopedService;
     TransientService = transientService;
 }
Ejemplo n.º 14
0
    public async Task <string> Transient([FromServices] TransientService service)
    {
        Console.WriteLine($"1. 注入服务Id: {service.Id}");

        var innerService1 = _serviceProvider.GetService <TransientService>();

        Console.WriteLine($"2. 方法内获取的服务Id: {innerService1!.Id}");

        var innerService2 = _serviceProvider.GetService <TransientService>();

        Console.WriteLine($"3. 方法内获取的服务Id: {innerService2!.Id}");

        return(service.Id);
    }
Ejemplo n.º 15
0
        public void CreateInstance_ExplicitParametersMixed_ReturnsInstance()
        {
            var service1  = new TransientService();
            var service2  = new SingletonService();
            var argument1 = "Hello";
            var argument2 = "Hello";

            var subject = ActivatorUtilities.CreateInstance <Subject>(ServiceProvider, service1, argument1, service2, argument2);

            Assert.NotNull(subject);
            Assert.Equal(service1, subject.Service1);
            Assert.Equal(service2, subject.Service2);
            Assert.Equal(argument1, subject.Argument1);
            Assert.Equal(argument2, subject.Argument2);
        }
Ejemplo n.º 16
0
        public InjectionController(ScopedService scopedCounter1, ScopedService scopedCounter2,
                                   SingletonService singletonCounter1,
                                   SingletonService singletonCounter2,
                                   TransientService transientCounter1,
                                   TransientService transientCounter2)
        {
            _scopedCounter1 = scopedCounter1;
            _scopedCounter2 = scopedCounter2;

            _singletonCounter1 = singletonCounter1;
            _singletonCounter2 = singletonCounter2;

            _transientCounter1 = transientCounter1;
            _transientCounter2 = transientCounter2;
        }
 public ScopeRepo1(SingletonService singleton, ScopeService scope, TransientService transient)
 {
     this.singleton = singleton;
     this.scope     = scope;
     this.transient = transient;
 }
 public HandlerWithTransientService(TransientService service)
 {
     Service = service;
 }
 public TypedClientWithTransientService(HttpClient httpClient, TransientService service)
 {
     HttpClient = httpClient;
     Service    = service;
 }
Ejemplo n.º 20
0
 public SingletonService(TransientService transient)
 {
     _transient = transient;
 }
Ejemplo n.º 21
0
 public ValuesController(SingletonService singletonService, ScopedService scopedService, TransientService transientService)
 {
     _singletonService = singletonService;
     _scopedService    = scopedService;
     _transientService = transientService;
 }
Ejemplo n.º 22
0
 public Subject(TransientService transientService)
 {
     TransientService = transientService;
 }
Ejemplo n.º 23
0
 public Subject(string argument, TransientService transientService)
 {
     Argument         = argument;
     TransientService = transientService;
 }
Ejemplo n.º 24
0
 public Service(TransientService transientService, ScopedService scopedService, SingletonService singletonService)
 {
     this.transientService = transientService;
     this.scopedService    = scopedService;
     this.singletonService = singletonService;
 }
Ejemplo n.º 25
0
 public Subject(TransientService service, string argument)
 {
     Service  = service;
     Argument = argument;
 }
Ejemplo n.º 26
0
 public Subject(TransientService service)
 {
     Service = service;
 }
 public MyController(TransientService service)
 {
     Service = service;
 }
Ejemplo n.º 28
0
 public CollectionServices(ScopeService scopeService, SingletonService singletonService, TransientService transientService)
 {
     _scopeService     = scopeService;
     _singletonService = singletonService;
     _transientService = transientService;
 }
 public CustomMiddleware(RequestDelegate next, TransientService transientService)
 {
     _next             = next;
     _transientService = transientService;
 }
 public SingletonRepo1(SingletonService singleton, TransientService transient)
 {
     this.singleton = singleton;
     this.transient = transient;
 }