コード例 #1
0
        public int GetService([FromServices] IMySingletonService mySingletonService1,
                              [FromServices] IMySingletonService mySingletonService2,
                              [FromServices] IMyTransientService myTransientService1,
                              [FromServices] IMyTransientService myTransientService2,
                              [FromServices] IMyScopeService myScopeService1,
                              [FromServices] IMyScopeService myScopeService2)
        {
            Console.WriteLine($"mySingleton1:{mySingletonService1.GetHashCode()}");
            Console.WriteLine($"mySingleton2:{mySingletonService2.GetHashCode()}");
            Console.WriteLine($"myTransient1:{myTransientService1.GetHashCode()}");
            Console.WriteLine($"myTransient2:{myTransientService2.GetHashCode()}");
            Console.WriteLine($"myScoped1:{myScopeService1.GetHashCode()}");
            Console.WriteLine($"myScoped2:{myScopeService2.GetHashCode()}");



            return(0);
        }
コード例 #2
0
        public int GetService([FromServices] IMySingletonService singletonService1,
                              [FromServices] IMySingletonService singletonService2,
                              [FromServices] IMyScopeService scopeService1,
                              [FromServices] IMyScopeService scopeService2,
                              [FromServices] IMyTransientService transientService1,
                              [FromServices] IMyTransientService transientService2)
        {
            Console.WriteLine($"{nameof(singletonService1)}:{singletonService1.GetHashCode()}");
            Console.WriteLine($"{nameof(singletonService2)}:{singletonService2.GetHashCode()}");

            Console.WriteLine($"{nameof(scopeService1)}:{scopeService1.GetHashCode()}");
            Console.WriteLine($"{nameof(scopeService2)}:{scopeService2.GetHashCode()}");

            Console.WriteLine($"{nameof(transientService1)}:{transientService1.GetHashCode()}");
            Console.WriteLine($"{nameof(transientService2)}:{transientService2.GetHashCode()}");

            Console.WriteLine("=========请求结束========");
            return(1);
        }
コード例 #3
0
        public void GetService([FromServices] IMySingletonService singleton1,
                               [FromServices] IMySingletonService singleton2,
                               [FromServices] IMyTransientService transient1,
                               [FromServices] IMyTransientService transient2,
                               [FromServices] IMyScopeService scoped1,
                               [FromServices] IMyScopeService scoped2)
        {
            Console.WriteLine($"singleton1:{singleton1.GetHashCode()}");
            Console.WriteLine($"singleton2:{singleton2.GetHashCode()}");


            Console.WriteLine($"transient1:{transient1.GetHashCode()}");
            Console.WriteLine($"transient2:{transient2.GetHashCode()}");

            Console.WriteLine($"scoped1:{scoped1.GetHashCode()}");
            Console.WriteLine($"scoped2:{scoped2.GetHashCode()}");

            Console.WriteLine($"========请求结束=======");
            //return 1;
        }