示例#1
0
 public FourthController(ILogger <FourthController> logger,
                         ILoggerFactory loggerFactory
                         , ITestServiceA testServiceA
                         , ITestServiceB testServiceB
                         , ITestServiceC testServiceC
                         , ITestServiceD testServiceD
                         , ITestServiceE testServiceE
                         , IServiceProvider serviceProvider
                         , IConfiguration configuration
                         , IUserService userService
                         , DbContext dbContext
                         )
 //, DbContext dbContext)
 {
     this._logger           = logger;
     this._loggerFactory    = loggerFactory;
     this._iTestServiceA    = testServiceA;
     this._iTestServiceB    = testServiceB;
     this._iTestServiceC    = testServiceC;
     this._iTestServiceD    = testServiceD;
     this._iTestServiceE    = testServiceE;
     this._iServiceProvider = serviceProvider;
     this._iConfiguration   = configuration;
     this._dbContext        = dbContext;
     this._iUserService     = userService;
 }
        public UsersController(ILoggerFactory factory,
                               ILogger <UsersController> logger,
                               ITestServiceA testServiceA,
                               ITestServiceB testServiceB,
                               ITestServiceC testServiceC,
                               ITestServiceD testServiceD,
                               IConfiguration configuration
                               , IUserService userService)
        {
            this._Factory        = factory;
            this._logger         = logger;
            this._ITestServiceA  = testServiceA;
            this._ITestServiceB  = testServiceB;
            this._ITestServiceC  = testServiceC;
            this._ITestServiceD  = testServiceD;
            this._IUserService   = userService;
            this._iConfiguration = configuration;
            this._iUserService   = userService;

            this._userList = this._iUserService.Query <Zhaoxi.EntityFrameworkCore31.Model.User>(u => u.Id > 1)
                             .OrderBy(u => u.Id)
                             .Skip(1)
                             .Take(5)
                             .Select(u => new Users()
            {
                UserID    = u.Id,
                UserEmail = u.Email,
                UserName  = u.Name
            }).ToList();
        }
示例#3
0
 public UserDAL(ITestServiceA testServiceA, ITestServiceB testServiceB, ITestServiceC testServiceC, ITestServiceD testServiceD, ITestServiceE testServiceE)
 {
     this._iTestServiceA = testServiceA;
     this._iTestServiceB = testServiceB;
     this._iTestServiceC = testServiceC;
     this._iTestServiceD = testServiceD;
     this._iTestServiceE = testServiceE;
 }
        public UsersController(ILoggerFactory factory,
                               ILogger <UsersController> logger,
                               ITestServiceA testServiceA,
                               ITestServiceB testServiceB,
                               ITestServiceC testServiceC,
                               ITestServiceD testServiceD,
                               IConfiguration configuration
                               , IUserService userService)
        {
            this._Factory        = factory;
            this._logger         = logger;
            this._ITestServiceA  = testServiceA;
            this._ITestServiceB  = testServiceB;
            this._ITestServiceC  = testServiceC;
            this._ITestServiceD  = testServiceD;
            this._IUserService   = userService;
            this._iConfiguration = configuration;
            this._iUserService   = userService;


            #region 为了测试方便,不从数据获取数据,使用内存
            //this._userList = this._iUserService.Query<Zhaoxi.EntityFrameworkCore31.Model.User>(u => u.Id > 1)
            //                    .OrderBy(u => u.Id)
            //                    .Skip(1)
            //                    .Take(5)
            //                    .Select(u => new Users()
            //                    {
            //                        UserID = u.Id,
            //                        UserEmail = u.Email,
            //                        UserName = u.Name
            //                    }).ToList();

            this._userList = new List <Users>()
            {
                new Users {
                    UserID = 1, UserName = "******"
                },
                new Users {
                    UserID = 2, UserName = "******"
                },
                new Users {
                    UserID = 3, UserName = "******"
                },
                new Users {
                    UserID = 4, UserName = "******"
                },
                new Users {
                    UserID = 5, UserName = "******"
                },
                new Users {
                    UserID = 6, UserName = "******"
                },
            };


            #endregion
        }
 public SecondController(ILoggerFactory loggerFactory, ILogger <SecondController> logger, ITestServiceA testServiceA, ITestServiceB testServiceB, ITestServiceC testServiceC, ITestServiceD testServiceD, IA ia, IUserService userService)
 {
     this._Factory       = loggerFactory;
     this._logger        = logger;
     this._ITestServiceA = testServiceA;
     this._ITestServiceB = testServiceB;
     this._ITestServiceC = testServiceC;
     this._ITestServiceD = testServiceD;
     this._IA            = ia;
     this._IUserService  = userService;
 }
 public SecondController(
     ITestServiceA testServiceA
     , ITestServiceB testServiceB
     , ITestServiceC testServiceC
     , ITestServiceD testServiceD)
 {
     this._iTestServiceA = testServiceA;
     this._iTestServiceB = testServiceB;
     this._iTestServiceC = testServiceC;
     this._iTestServiceD = testServiceD;
 }
示例#7
0
 public FourthController(ILoggerFactory factory, ILogger <SecondController> ilogger,
                         ITestServiceA testServiceA,
                         ITestServiceB testServiceB,
                         ITestServiceC testServiceC,
                         ITestServiceD testServiceD,
                         IA a)
 {
     _factory      = factory;
     _ilogger      = ilogger;
     _testServiceA = testServiceA;
     _testServiceB = testServiceB;
     _testServiceC = testServiceC;
     _testServiceD = testServiceD;
     _a            = a;
 }
示例#8
0
 public UsersController(ILoggerFactory factory,
                        ILogger <SecondController> logger,
                        ITestServiceA testServiceA,
                        ITestServiceB testServiceB,
                        ITestServiceC testServiceC,
                        ITestServiceD testServiceD,
                        IA a)
 {
     this._Factory       = factory;
     this._logger        = logger;
     this._ITestServiceA = testServiceA;
     this._ITestServiceB = testServiceB;
     this._ITestServiceC = testServiceC;
     this._ITestServiceD = testServiceD;
     this._IA            = a;
 }
示例#9
0
 public FourthController(ILogger <FourthController> logger
                         , ITestServiceA testServiceA
                         , ITestServiceB testServiceB
                         , ITestServiceC testServiceC
                         , ITestServiceD testServiceD
                         , ITestServiceE testServiceE
                         , IA a)
 {
     this._logger        = logger;
     this._iTestServiceA = testServiceA;
     this._iTestServiceB = testServiceB;
     this._iTestServiceC = testServiceC;
     this._iTestServiceD = testServiceD;
     this._iTestServiceE = testServiceE;
     this._ia            = a;
 }
示例#10
0
 public SecondController(ILoggerFactory loggerFactory,
                         ILogger <SecondController> logger,
                         ITestServiceA testServiceA,
                         ITestServiceB testServiceB,
                         ITestServiceC testServiceC,
                         ITestServiceD testServiceD,
                         IA a)
 {
     _loggerFactory = loggerFactory;
     _logger        = logger;
     _testServiceA  = testServiceA;
     _testServiceB  = testServiceB;
     _testServiceC  = testServiceC;
     _testServiceD  = testServiceD;
     _a             = a;
 }
示例#11
0
 public SecondController(ILogger <SecondController> logger,
                         ILoggerFactory loggerFactory,
                         ITestServiceA testServiceA,
                         ITestServiceB testServiceB,
                         ITestServiceC testServiceC,
                         ITestServiceD testServiceD,
                         ITestServiceE testServiceE,
                         IServiceProvider iServiceProvider
                         )
 {
     _logger                = logger;
     this._loggerFactory    = loggerFactory;
     this._iTestServiceA    = testServiceA;
     this._iTestServiceB    = testServiceB;
     this._iTestServiceC    = testServiceC;
     this._iTestServiceD    = testServiceD;
     this._iTestServiceE    = testServiceE;
     this._iServiceProvider = iServiceProvider;
 }
 public ThirdController(ILogger <ThirdController> logger,
                        ILoggerFactory loggerFactory
                        , ITestServiceA testServiceA
                        , ITestServiceB testServiceB
                        , ITestServiceC testServiceC
                        , ITestServiceD testServiceD
                        , ITestServiceE testServiceE
                        , IServiceProvider serviceProvider
                        , IConfiguration configuration)
 {
     this._logger           = logger;
     this._loggerFactory    = loggerFactory;
     this._iTestServiceA    = testServiceA;
     this._iTestServiceB    = testServiceB;
     this._iTestServiceC    = testServiceC;
     this._iTestServiceD    = testServiceD;
     this._iTestServiceE    = testServiceE;
     this._iServiceProvider = serviceProvider;
     this._iConfiguration   = configuration;
 }
示例#13
0
 public SecondController(ILoggerFactory factory,
                         ILogger <SecondController> logger,
                         CyfMYSQLContext mysqlcontext,
                         CyfMSSQLContext mssqlcontext,
                         ITestServiceA testServiceA,
                         ITestServiceB testServiceB,
                         ITestServiceC testServiceC,
                         ITestServiceD testServiceD,
                         IA a)
 {
     this._Factory       = factory;
     this._logger        = logger;
     this._ITestServiceA = testServiceA;
     this._ITestServiceB = testServiceB;
     this._ITestServiceC = testServiceC;
     this._ITestServiceD = testServiceD;
     this._IA            = a;
     this._Mysqlcontext  = mysqlcontext;
     this._Mssqlcontext  = mssqlcontext;
 }
 /// <summary>
 /// 来自DI依赖注入---构造函数注入---构造A对象依赖B对象,自动初始化B对象传入
 ///
 /// 有个容器,负责构造SecondController(反射)--反射构造函数--需要B--再构造B---然后再构造A
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="loggerFactory"></param>
 public SecondController(ILogger <SecondController> logger,
                         ILoggerFactory loggerFactory
                         , ITestServiceA testServiceA
                         , ITestServiceB testServiceB
                         , ITestServiceC testServiceC
                         , ITestServiceD testServiceD
                         , ITestServiceE testServiceE
                         , IServiceProvider serviceProvider)
 //一次注入这么多,可能用不上,能不能我自己生成? 不建议,
 //1 大部分对象生成其实很快,且不占资源--特殊可以自己控制
 //2 对象生命周期不同,注入的是跟controller的,action是跟方法的
 {
     this._logger           = logger;
     this._loggerFactory    = loggerFactory;
     this._iTestServiceA    = testServiceA;
     this._iTestServiceB    = testServiceB;
     this._iTestServiceC    = testServiceC;
     this._iTestServiceD    = testServiceD;
     this._iTestServiceE    = testServiceE;
     this._iServiceProvider = serviceProvider;
 }
示例#15
0
 public UserDAL(ITestServiceA testServiceA, ITestServiceB testServiceB
                , ITestServiceC testServiceC, ITestServiceD testServiceD)
 {
     this._iTestServiceA = testServiceA;
     this._iTestServiceB = testServiceB;
 }
示例#16
0
 public TestServiceB(ITestServiceD testServiceD)
 {
 }
示例#17
0
        static void Main(string[] args)
        {
            ///容器的使用:
            ///            实例化一个容器;
            ///            注册
            ///            获取服务
            IServiceCollection container = new ServiceCollection();

            // IServiceCollection
            container.AddTransient <ITestServiceA, TestServiceA>();     // 瞬时生命周期  每一次获取的对象都是新的对象
            container.AddSingleton <ITestServiceB, TestServiceB>();     // 单例生命周期  在容器中永远只有当前这一个
            container.AddScoped <ITestServiceC, TestServiceC>();        //当前请求作用域内  只有当前这个实例

            container.AddSingleton <ITestServiceD>(new TestServiceD()); // 也是单例生命周期

            ServiceProvider provider = container.BuildServiceProvider();

            ITestServiceA testA  = provider.GetService <ITestServiceA>();
            ITestServiceA testA1 = provider.GetService <ITestServiceA>();

            Console.WriteLine(object.ReferenceEquals(testA, testA1));

            ITestServiceB testB  = provider.GetService <ITestServiceB>();
            ITestServiceB testB1 = provider.GetService <ITestServiceB>();

            Console.WriteLine(object.ReferenceEquals(testB, testB1));

            ITestServiceC testC  = provider.GetService <ITestServiceC>();
            ITestServiceC testC1 = provider.GetService <ITestServiceC>();

            Console.WriteLine(object.ReferenceEquals(testC, testC1));

            IServiceScope scope  = provider.CreateScope();
            ITestServiceC testc3 = provider.GetService <ITestServiceC>();
            var           testc4 = scope.ServiceProvider.GetService <ITestServiceC>();

            Console.WriteLine(object.ReferenceEquals(testc3, testc4));

            ITestServiceD testD  = provider.GetService <ITestServiceD>();
            ITestServiceD testD1 = provider.GetService <ITestServiceD>();

            Console.WriteLine(object.ReferenceEquals(testD, testD1));

            //Console.WriteLine("Hello World!");

            //var user = new
            //{
            //    Id = 11,
            //    Name = "Richard"
            //};
            //Console.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(user));


            //Console.WriteLine("**************************************");
            //{
            //    SharpSix six = new SharpSix();
            //    People people = new People()
            //    {
            //        Id = 505,
            //        Name = "马尔凯蒂"
            //    };
            //    six.Show(people);
            //}

            //Console.WriteLine("**************************************");
            //{
            //    SharpSeven seven = new SharpSeven();
            //    seven.Show();
            //}
        }
示例#18
0
        static void Main(string[] args)
        {
            ///容器的使用:
            ///            实例化一个容器;
            ///            注册
            ///            获取服务
            IServiceCollection container = new ServiceCollection();

            // IServiceCollection
            container.AddTransient <ITestServiceA, TestServiceA>();     // 瞬时生命周期  每一次获取的对象都是新的对象
            container.AddSingleton <ITestServiceB, TestServiceB>();     // 单例生命周期  在容器中永远只有当前这一个
            container.AddScoped <ITestServiceC, TestServiceC>();        //当前请求作用域内  只有当前这个实例

            container.AddSingleton <ITestServiceD>(new TestServiceD()); // 也是单例生命周期

            ServiceProvider provider = container.BuildServiceProvider();

            ITestServiceA testA  = provider.GetService <ITestServiceA>();
            ITestServiceA testA1 = provider.GetService <ITestServiceA>();

            Console.WriteLine(object.ReferenceEquals(testA, testA1));

            ITestServiceB testB  = provider.GetService <ITestServiceB>();
            ITestServiceB testB1 = provider.GetService <ITestServiceB>();

            Console.WriteLine(object.ReferenceEquals(testB, testB1));

            ITestServiceC testC  = provider.GetService <ITestServiceC>();
            ITestServiceC testC1 = provider.GetService <ITestServiceC>();

            Console.WriteLine(object.ReferenceEquals(testC, testC1));

            IServiceScope scope  = provider.CreateScope();
            ITestServiceC testc3 = provider.GetService <ITestServiceC>();
            var           testc4 = scope.ServiceProvider.GetService <ITestServiceC>();

            Console.WriteLine(object.ReferenceEquals(testc3, testc4));

            ITestServiceD testD  = provider.GetService <ITestServiceD>();
            ITestServiceD testD1 = provider.GetService <ITestServiceD>();

            Console.WriteLine(object.ReferenceEquals(testD, testD1));



            /*
             * Console.WriteLine("Hello World!");
             *
             * var user = new {
             *  Id=11,
             *  Name="HelloDavy",
             *  Age=18
             * };
             *
             * Console.WriteLine(user);
             * var options = new JsonSerializerOptions();
             * options.Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Create(UnicodeRanges.All);
             * var json = JsonSerializer.Serialize(user,options);
             * Console.WriteLine(json);
             *
             * Console.WriteLine("**************************************");
             * {
             *  SharpSix six = new SharpSix();
             *  People people = new People()
             *  {
             *      Id = 505,
             *      Name = "马尔凯蒂"
             *  };
             *  six.Show(people);
             * }
             *
             * Console.WriteLine("**************************************");
             * {
             *  SharpSeven seven = new SharpSeven();
             *  seven.Show();
             * }*/
        }