示例#1
0
        public HomeController(ISingletonService singletonService1,
                              ISingletonService singletonService2,
                              ITransientService transientService1,
                              ITransientService transientService2,
                              IScopeService scopedService1,
                              IScopeService scopedService2)
        {
            this.singletonService1 = singletonService1;
            this.singletonService2 = singletonService2;

            this.transientService1 = transientService1;
            this.transientService2 = transientService2;

            this.scopedService1 = scopedService1;
            this.scopedService2 = scopedService2;
        }
        public IActionResult Index([FromServices] ISingletonService singletonService2)
        {
            var viewModel = new HomeViewModel
            {
                Scoped     = scopedService.GetHashCode(),
                Scoped2    = scopedService2.GetHashCode(),
                Singleton  = singletonService.GetHashCode(),
                Transient  = transientService.GetHashCode(),
                Transient2 = transientService2.GetHashCode(),
            };

            //Use the singleton service which is injected via methos injection
            var singletonObjectHashCode = singletonService2.GetHashCode();

            return(View(viewModel));
        }
示例#3
0
        public HomeController(ITransientService transientService1,
                              ITransientService transientService2,
                              IScopedService scopedService1,
                              IScopedService scopedService2,
                              ISingletonService singletonService1,
                              ISingletonService singletonService2)
        {
            _transientService1 = transientService1;
            _transientService2 = transientService2;

            _scopedService1 = scopedService1;
            _scopedService2 = scopedService2;

            _singletonService1 = singletonService1;
            _singletonService2 = singletonService2;
        }
示例#4
0
 public HomeController(ILogger <HomeController> logger,
                       ITransientService transientService1,
                       ITransientService transientService2,
                       IScopedService scopedService1,
                       IScopedService scopedService2,
                       ISingletonService singletonService1,
                       ISingletonService singletonService2)
 {
     _logger            = logger;
     _transientService1 = transientService1;
     _transientService2 = transientService2;
     _scopedService1    = scopedService1;
     _scopedService2    = scopedService2;
     _singletonService1 = singletonService1;
     _singletonService2 = singletonService2;
 }
        public static IActionResult Run(
            [HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req,
            [Inject] ITransientService transientService,
            [Inject] IScopedService scopedService,
            [Inject] ISingletonService singletonService,
            ILogger logger)
        {
            logger.LogInformation("C# HTTP trigger function processed a request.");

            string result = String.Join(Environment.NewLine, new[] {
                $"Transient: {transientService.GetCounter()}",
                $"Scoped: {scopedService.GetCounter()}",
                $"Singleton: {singletonService.GetCounter()}",
            });

            return(new OkObjectResult(result));
        }
示例#6
0
        public string GetServices([FromServices] ISingletonService singletonService1, [FromServices] ISingletonService singletonService2,
                                  [FromServices] ITransientService transientService1, [FromServices] ITransientService transientService2,
                                  [FromServices] IScopedService scopedService1, [FromServices] IScopedService scopedService2)
        {
            Console.WriteLine("***************************************************************");
            Console.WriteLine($"Scoped:   {scopedService1.Guid}");
            Console.WriteLine($"Scoped:   {scopedService2.Guid}");
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine($"Transient:   {transientService1.Guid}");
            Console.WriteLine($"Transient:   {transientService2.Guid}");
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine($"Singleton:   {singletonService1.Guid}");
            Console.WriteLine($"Singleton:   {singletonService2.Guid}");
            Console.WriteLine(Environment.NewLine);
            Console.WriteLine("***************************************************************");

            return("success");
        }
        public int GetService([FromServices] ISingletonService singleton1,
                              [FromServices] ISingletonService singleton2,
                              [FromServices] IScopedService scoped1,
                              [FromServices] IScopedService scoped2,
                              [FromServices] ITransientService transient1,
                              [FromServices] ITransientService transient2)
        {
            Console.WriteLine($"singleton1:{singleton1.GetHashCode()}");
            Console.WriteLine($"singleton2:{singleton2.GetHashCode()}");

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

            Console.WriteLine($"transient1:{transient1.GetHashCode()}");
            Console.WriteLine($"transient2:{transient2.GetHashCode()}");
            Console.WriteLine($"===================请求结束=========================");

            return(1);
        }
        public IActionResult MyGetTest2([FromServices] ISingletonService singletonService1,
                                        [FromServices] ISingletonService singletonService2, [FromServices] IScopeService scopeService1,
                                        [FromServices] IScopeService scopeService2, [FromServices] ITransientService transientService1, [FromServices] ITransientService transientService2)
        {
            Console.WriteLine($"构造函数 中获取的 singletonService1 的 hashCode :{ _singletonService.GetHashCode()}");
            Console.WriteLine($"构造函数 中获取的 scopeService1 的 hashCode :{ _scopeService.GetHashCode()}");
            Console.WriteLine($"构造函数 中获取的 transientService1 的 hashCode :{ _transientService.GetHashCode()}");

            Console.WriteLine($"HttpContext 中获取的 singletonService1 的 hashCode :{ singletonService1.GetHashCode()}");
            Console.WriteLine($"HttpContext 中获取的 singletonService2 的 hashCode :{ singletonService2.GetHashCode()}");
            Console.WriteLine($"HttpContext 中获取的 scopeService1 的 hashCode :{ scopeService1.GetHashCode()}");
            Console.WriteLine($"HttpContext 中获取的 scopeService2 的 hashCode :{ scopeService2.GetHashCode()}");
            Console.WriteLine($"HttpContext 中获取的 transientService1 的 hashCode :{ transientService1.GetHashCode()}");
            Console.WriteLine($"HttpContext 中获取的 transientService2 的 hashCode :{ transientService2.GetHashCode()}");
            //serviceProvider对象
            Console.WriteLine($"HttpContext的ServiceProvider 的 hashCode :{ HttpContext.RequestServices.GetHashCode()}");

            return(Content("MyGetTest"));
        }
 public HomeController(ILogger <HomeController> logger
                       , IScopedService scopedService
                       , ISingletonService singletonService
                       , ITransientService transientService
                       , IScopedService scopedService2
                       , ISingletonService singletonService2
                       , ITransientService transientService2
                       , IGuidService guidService
                       )
 {
     _logger                = logger;
     this.scopedService     = scopedService;
     this.singletonService  = singletonService;
     this.transientService  = transientService;
     this.scopedService2    = scopedService2;
     this.singletonService2 = singletonService2;
     this.transientService2 = transientService2;
     this.guidService       = guidService;
 }
        public HomeController(ITransientService transientService1,
                              ITransientService transientService2,
                              IScopedService scopedService1,
                              IScopedService scopedService2,
                              ISingletonService singletonService1,
                              ISingletonService singletonService2,
                              IEnumerable <ITranscriptionService> transcriptionServices)
        {
            _transientService1 = transientService1;
            _transientService2 = transientService2;

            _scopedService1 = scopedService1;
            _scopedService2 = scopedService2;

            _singletonService1 = singletonService1;
            _singletonService2 = singletonService2;

            _transcriptionServices = transcriptionServices;
        }
示例#11
0
 public RevalidationStarter(
     IRevalidationJobStateService jobState,
     IPackageRevalidationStateService packageState,
     ISingletonService singletonService,
     IRevalidationThrottler throttler,
     IHealthService healthService,
     IRevalidationQueue revalidationQueue,
     IPackageValidationEnqueuer validationEnqueuer,
     ITelemetryService telemetryService,
     ILogger <RevalidationStarter> logger)
 {
     _jobState           = jobState ?? throw new ArgumentNullException(nameof(jobState));
     _packageState       = packageState ?? throw new ArgumentNullException(nameof(packageState));
     _singletonService   = singletonService ?? throw new ArgumentNullException(nameof(singletonService));
     _throttler          = throttler ?? throw new ArgumentNullException(nameof(throttler));
     _healthService      = healthService ?? throw new ArgumentNullException(nameof(healthService));
     _revalidationQueue  = revalidationQueue ?? throw new ArgumentNullException(nameof(revalidationQueue));
     _validationEnqueuer = validationEnqueuer ?? throw new ArgumentNullException(nameof(validationEnqueuer));
     _telemetryService   = telemetryService ?? throw new ArgumentNullException(nameof(telemetryService));
     _logger             = logger ?? throw new ArgumentNullException(nameof(logger));
 }
示例#12
0
        public HomeController(ILogger <HomeController> logger,
                              IDateTimeData dateTimeData,
                              IWelcomeServices welcomeServices,
                              IHttpClientFactory myhttpclientfactory,
                              IOptions <AppSetting> Setting,

                              ITransientService guidTransientService,
                              IScopedService guidScopedService,
                              ISingletonService guidSingletonService

                              )
        {
            _logger              = logger;
            _dateTimeData        = dateTimeData;
            _WelcomeServices     = welcomeServices;
            _myhttpclientfactory = myhttpclientfactory;
            _Setting             = Setting;

            _guidTransientService = guidTransientService;
            _guidScopedService    = guidScopedService;
            _guidSingletonService = guidSingletonService;
        }
示例#13
0
        public override void Init()
        {
            log.Debug("MvcApplication.Int");
            log.Debug($"MvcApplication.Int:已注册的HttpModule{new JavaScriptSerializer().Serialize(Modules)}");
            log.Debug($"MvcApplication.Int:已注册的委托事件{new JavaScriptSerializer().Serialize(Events)}");

            PreSendRequestHeaders += MvcApplication_PreSendRequestHeaders;
            MapRequestHandler     += MvcApplication_MapRequestHandler;
            Disposed                  += MvcApplication_Disposed;
            BeginRequest              += MvcApplication_BeginRequest;
            AuthenticateRequest       += MvcApplication_AuthenticateRequest;
            PostAuthenticateRequest   += MvcApplication_PostAuthenticateRequest;
            AuthorizeRequest          += MvcApplication_AuthorizeRequest;
            PostAuthorizeRequest      += MvcApplication_PostAuthorizeRequest;
            ResolveRequestCache       += MvcApplication_ResolveRequestCache;
            PostResolveRequestCache   += MvcApplication_PostResolveRequestCache;
            PreSendRequestContent     += MvcApplication_PreSendRequestContent;
            PostMapRequestHandler     += MvcApplication_PostMapRequestHandler;
            PostLogRequest            += MvcApplication_PostLogRequest;
            RequestCompleted          += MvcApplication_RequestCompleted;
            PostAcquireRequestState   += MvcApplication_PostAcquireRequestState;
            PreRequestHandlerExecute  += MvcApplication_PreRequestHandlerExecute;
            PostRequestHandlerExecute += MvcApplication_PostRequestHandlerExecute;
            ReleaseRequestState       += MvcApplication_ReleaseRequestState;
            PostReleaseRequestState   += MvcApplication_PostReleaseRequestState;
            UpdateRequestCache        += MvcApplication_UpdateRequestCache;
            PostUpdateRequestCache    += MvcApplication_PostUpdateRequestCache;
            LogRequest                += MvcApplication_LogRequest;
            AcquireRequestState       += MvcApplication_AcquireRequestState;
            EndRequest                += MvcApplication_EndRequest;
            Error += MvcApplication_Error;
            base.Init();
            log.Debug($"MvcApplication.Int:已注册的HttpModule{new JavaScriptSerializer().Serialize(Modules)}");
            log.Debug($"MvcApplication.Int:已注册的委托事件{new JavaScriptSerializer().Serialize(Events)}");

            SingletonService = UnityConfig.container.Resolve <ISingletonService>();

            SingletonService.ToDoSomeThing();
        }
示例#14
0
        public WeatherForecastController(
            ILogger <WeatherForecastController> logger,
            ITransientService transientService1,
            ITransientService transientService2,
            IScopedService scopedService1,
            IScopedService scopedService2,
            ISingletonService singletonService1,
            ISingletonService singletonService2,
            IMapper mapper,
            AppDbContext context
            )
        {
            _logger  = logger;
            _mapper  = mapper;
            _context = context;

            _transientService1 = transientService1;
            _transientService2 = transientService2;
            _scopedService1    = scopedService1;
            _scopedService2    = scopedService2;
            _singletonService1 = singletonService1;
            _singletonService2 = singletonService2;
        }
        public DIController(ISingletonService singletonService,
                            IScopedService scopedService,
                            ITransientService transientService,
                            ISingletonService singletonService2,
                            IScopedService scopedService2,
                            ITransientService transientService2,
                            IAnotherDependency anotherDependency,
                            IServiceScopeFactory serviceScopeFactory,
                            TesteConfig testeConfig)
        {
            this.singletonService = singletonService;
            this.scopedService    = scopedService;
            this.transientService = transientService;

            this.singletonService2 = singletonService2;
            this.scopedService2    = scopedService2;
            this.transientService2 = transientService2;

            this.anotherDependency = anotherDependency;

            this.serviceScopeFactory = serviceScopeFactory;

            this.testeConfig = testeConfig;
        }
 public AggregateService(IInstanceService instance, IScopedService scoped, ITransientService transient, ISingletonService singleton)
 {
     Instance  = instance;
     Scoped    = scoped;
     Transient = transient;
     Singleton = singleton;
 }
示例#17
0
 /// <summary>
 /// 两种注入方式:构造函数注入....FromServices注入....
 /// </summary>
 /// <param name="logger"></param>
 /// <param name="_singletonService"></param>
 /// <param name="_scopedService"></param>
 /// <param name="_transientService"></param>
 /// <param name="_singletonService2"></param>
 /// <param name="_scopedService2"></param>
 /// <param name="_transientService2"></param>
 public WeatherForecastController(ILogger <WeatherForecastController> logger, ISingletonService _singletonService, IScopedService _scopedService, ITransientService _transientService, ISingletonService _singletonService2, IScopedService _scopedService2, ITransientService _transientService2)
 {
     Console.WriteLine($"singleton:{_singletonService.GetHashCode()}");
     Console.WriteLine($"singleton:{_singletonService2.GetHashCode()}");
     Console.WriteLine($"scoped:{_scopedService.GetHashCode()}");
     Console.WriteLine($"scoped:{_scopedService2.GetHashCode()}");
     Console.WriteLine($"transient:{_transientService.GetHashCode()}");
     Console.WriteLine($"transient:{_transientService2.GetHashCode()}");
     _logger = logger;
 }
示例#18
0
 public DILifeTimeService(ISingletonService singleton, ITransientService transient, IScopedService scoped)
 {
     _singleton = singleton;
     _transient = transient;
     _scoped    = scoped;
 }
示例#19
0
 public SomeCommandFilter(ISingletonService service)
 {
     _service = service;
 }
 public SingletonConsumer(IUnityContainer container, ISingletonService singleton)
 {
     ContainerId      = container.GetHashCode();
     SingletonService = singleton;
 }
示例#21
0
 public HomeController(ISingletonService singletonService, IScopedService scopedService, ITransientService transientService)
 {
     _singletonService = singletonService;
     _scopedService    = scopedService;
     _transientService = transientService;
 }
示例#22
0
        public HomeController(IConfiguration configuration, ITransientService transientService, ISingletonService singletonService, IScopedService scopedService, ILogger <HomeController> logger)
        {
            _configuration    = configuration;
            _transientService = transientService;
            _scopedService    = scopedService;
            _singletonService = singletonService;

            _logger = logger;
        }
示例#23
0
 public ServicesModel(ISingletonService singletonService, ITransientService transientService, IScopedService scopedService)
 {
     SingletonService = singletonService;
     TransientService = transientService;
     ScopedService    = scopedService;
 }
示例#24
0
 public ServiceWithMultipleCostructorsAndOneImporting(ISingletonService singleton)
 {
     Singleton = singleton;
 }
示例#25
0
 public HomeController(IAggregateService aggregateService, ITransientService transientService, IScopedService scopedService, IInstanceService instanceService, ISingletonService singletonService)
 {
     AggregateService = aggregateService;
     TransientService = transientService;
     ScopedService    = scopedService;
     SingletonService = singletonService;
     InstanceService  = instanceService;
 }
示例#26
0
 public HomeController(ILogger <HomeController> logger, ISingletonService s5)
 {
     _services5 = s5;
     _logger    = logger;
 }
示例#27
0
 public EnumerableService3(ITransientService transient, ISingletonService singleton)
 {
     Transient = transient;
     Singleton = singleton;
 }
示例#28
0
 public SomeQueriesMiddleware(ISingletonService service)
 {
     _service = service;
 }
示例#29
0
 public ValuesController(IScopedService scopedService, ITransientService transientService, ISingletonService singletonService, IEnumerable <ICollector> collectors)
 {
     _scopedService    = scopedService;
     _transientService = transientService;
     _singletonService = singletonService;
     _collectors       = collectors;
 }
示例#30
0
 public ServiceWithMultipleCostructors(ISingletonService singleton)
 {
     Singleton = singleton;
 }