public IEnumerable <WeatherForecast> Get(
            [FromServices] ITestTransient testTransient1, // 在参数中通过增加[FromService]对参数进行注入
            [FromServices] ITestTransient testTransient2,
            [FromServices] ITestScoped testScoped1,
            [FromServices] ITestScoped testScoped2,
            [FromServices] ITestSignleton testSignleton1,
            [FromServices] ITestSignleton testSignleton2
            )
        {
            Console.WriteLine($"--------------请求开始--------------");
            Console.WriteLine($"Transient1 HashCode:{testTransient1.GetHashCode()}");
            Console.WriteLine($"Transient2 HashCode:{testTransient2.GetHashCode()}");
            Console.WriteLine($"ITestScoped1 HashCode:{testScoped1.GetHashCode()}");
            Console.WriteLine($"ITestScoped2 HashCode:{testScoped2.GetHashCode()}");
            Console.WriteLine($"ITestSignleton1 HashCode:{testSignleton1.GetHashCode()}");
            Console.WriteLine($"ITestSignleton2 HashCode:{testSignleton2.GetHashCode()}");
            Console.WriteLine($"--------------请求结束--------------");

            var rng = new Random();

            return(Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateTime.Now.AddDays(index),
                TemperatureC = rng.Next(-20, 55),
                Summary = Summaries[rng.Next(Summaries.Length)]
            })
                   .ToArray());
        }
Ejemplo n.º 2
0
 public void DependencyResolver_GetService_should_return_null_for_registered_interface_types()
 {
     using (ApplicationDependencyInjection di = CreateMvcDIWithTestServiceRegistrations(out IDependencyResolver resolver))
     {
         ITestTransient service = resolver.GetService <ITestTransient>();
         service.ShouldBeNull();
     }
 }
Ejemplo n.º 3
0
        public DemoController(ITestOne testOne, ITestTwo testTwo, ITestThree testThree
                              , ITestTransient testTransient, ITestScoped testScoped, ITestSingleton testSingleton, TestService testService
                              , IOptions <ConfigOptions> options
                              )
        {
            this._cfgContent = options.Value;

            _testOne   = testOne;
            _testTwo   = testTwo;
            _testThree = testThree;

            _testTransient = testTransient;
            _testScoped    = testScoped;
            _testSingleton = testSingleton;
            _testService   = testService;
        }
Ejemplo n.º 4
0
 public ConstructorIOCTest(ITestTransient test)
 {
     m_test = test;
 }
Ejemplo n.º 5
0
 public TestService(ITestTransient testTransient, ITestScoped testScoped, ITestSingleton testSingleton)
 {
     TestTransient = testTransient;
     TestScoped    = testScoped;
     TestSingleton = testSingleton;
 }
Ejemplo n.º 6
0
 public ValuesController(ITestTransient testTransient, ITestScoped testScoped, ITestSingleton testSingleton)
 {
     _testTransient = testTransient;
     _testScoped    = testScoped;
     _testSingleton = testSingleton;
 }