How make data from a HostedService available in my PipelineWhere should static files middleware be in the ASP.NET Core pipeline?Configure HttpClientFactory to use data from the current request contextWhat is the simplest possible way to insert data into Sql Server from dotnetcoreStopAsync with ExecuteAsync on BackgroundServiceHow does asp.net core 2.1 handle %20 as a querystring parameterHow to stop a request pipeline at actionfilter level using ASP.NET CORE 2.1?How to make a route available only after login in asp.net core 2.1?Not able to get “member of ” details from DirectorySearcher post deploy the asp.net core 2.1 in IIS.net core 2.2, SIGNALR, how to retrive data from server to client in “then” statement

Is it possible to take a database offline when doing a backup using an SQL job?

Avoiding dust scattering when you drill

How to identify whether a publisher is genuine or not?

Beyond Futuristic Technology for an Alien Warship?

Garage door sticks on a bolt

What action is recommended if your accommodation refuses to let you leave without paying additional fees?

Why isn't there armor to protect from spells in the Potterverse?

What would happen if I build a half bath without permits?

Why most footers have a background color has a divider of section?

What are one's options when facing religious discrimination at the airport?

How does Monks' Improved Unarmored Movement work out of combat?

How many stack cables would be needed if we want to stack two 3850 switches

How do my husband and I get over our fear of having another difficult baby?

Knights and Knaves: What does C say?

French license plates

I transpose the source code, you transpose the input!

IEEE 754 square root with Newton-Raphson

What would influence an alien race to map their planet in a way other than the traditional map of the Earth

Isn't the detector always measuring, and thus always collapsing the state?

Windows 10 deletes lots of tiny files super slowly. Anything that can be done to speed it up?

Realistically, how much do you need to start investing?

Delete n lines skip 1 line script

Which Catholic priests were given diplomatic missions?

Is the "spacetime" the same thing as the mathematical 4th dimension?



How make data from a HostedService available in my Pipeline


Where should static files middleware be in the ASP.NET Core pipeline?Configure HttpClientFactory to use data from the current request contextWhat is the simplest possible way to insert data into Sql Server from dotnetcoreStopAsync with ExecuteAsync on BackgroundServiceHow does asp.net core 2.1 handle %20 as a querystring parameterHow to stop a request pipeline at actionfilter level using ASP.NET CORE 2.1?How to make a route available only after login in asp.net core 2.1?Not able to get “member of ” details from DirectorySearcher post deploy the asp.net core 2.1 in IIS.net core 2.2, SIGNALR, how to retrive data from server to client in “then” statement






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I used this example to create a timed background task. Using this background task I have a value that is updated every x seconds, which works fine.



However, I want to be able to use this value in my middleware pipeline. How is this achieved? Can I used someting like a global variable or reference the HostedService in some way?



Timed background service



Started using ConfigureServices
services.AddHostedService<<>>();




public class TimerService : IHostedService, IDisposable

private readonly ILogger _logger;
private Timer _timer;

public TimerService (ILogger<TimerService> logger)

_logger = logger;


public Task StartAsync(CancellationToken cancellationToken)

_logger.LogInformation("Timed Background Service is starting.");

_timer = new Timer(DoWork, null, TimeSpan.Zero,
TimeSpan.FromSeconds(1));

return Task.CompletedTask;


private async void DoWork(object state)

//Do your stuff here
await Task.Delay(50);
_logger.LogInformation("Timed Background Service is executing.");


public Task StopAsync(CancellationToken cancellationToken)

_logger.LogInformation("Timed Background Service is stopping.");

_timer?.Change(Timeout.Infinite, 0);

return Task.CompletedTask;


public void Dispose()

_timer?.Dispose();





Middleware pipeline



started using Configure



 public async Task Invoke(HttpContext context, ILogger<APIKeyHandler> logger, IConfiguration configuration)

_logger = logger;

bool KeyInHeader = context.Request.Headers.ContainsKey("Key");

if (KeyInHeader)

if (context.Request.Headers["Key"] = *!!VALUE COLLECTED USING THE TimerService*!!)

context.Response.StatusCode = (int)HttpStatusCode.NoContent;
await context.Response.WriteAsync($"Executed");





There is currently no way to get the values from the TimerService. I would like to be able to reference Timerservice.LatestValue or something. If this is not the way to I would love to get some directions.










share|improve this question






























    0















    I used this example to create a timed background task. Using this background task I have a value that is updated every x seconds, which works fine.



    However, I want to be able to use this value in my middleware pipeline. How is this achieved? Can I used someting like a global variable or reference the HostedService in some way?



    Timed background service



    Started using ConfigureServices
    services.AddHostedService<<>>();




    public class TimerService : IHostedService, IDisposable

    private readonly ILogger _logger;
    private Timer _timer;

    public TimerService (ILogger<TimerService> logger)

    _logger = logger;


    public Task StartAsync(CancellationToken cancellationToken)

    _logger.LogInformation("Timed Background Service is starting.");

    _timer = new Timer(DoWork, null, TimeSpan.Zero,
    TimeSpan.FromSeconds(1));

    return Task.CompletedTask;


    private async void DoWork(object state)

    //Do your stuff here
    await Task.Delay(50);
    _logger.LogInformation("Timed Background Service is executing.");


    public Task StopAsync(CancellationToken cancellationToken)

    _logger.LogInformation("Timed Background Service is stopping.");

    _timer?.Change(Timeout.Infinite, 0);

    return Task.CompletedTask;


    public void Dispose()

    _timer?.Dispose();





    Middleware pipeline



    started using Configure



     public async Task Invoke(HttpContext context, ILogger<APIKeyHandler> logger, IConfiguration configuration)

    _logger = logger;

    bool KeyInHeader = context.Request.Headers.ContainsKey("Key");

    if (KeyInHeader)

    if (context.Request.Headers["Key"] = *!!VALUE COLLECTED USING THE TimerService*!!)

    context.Response.StatusCode = (int)HttpStatusCode.NoContent;
    await context.Response.WriteAsync($"Executed");





    There is currently no way to get the values from the TimerService. I would like to be able to reference Timerservice.LatestValue or something. If this is not the way to I would love to get some directions.










    share|improve this question


























      0












      0








      0








      I used this example to create a timed background task. Using this background task I have a value that is updated every x seconds, which works fine.



      However, I want to be able to use this value in my middleware pipeline. How is this achieved? Can I used someting like a global variable or reference the HostedService in some way?



      Timed background service



      Started using ConfigureServices
      services.AddHostedService<<>>();




      public class TimerService : IHostedService, IDisposable

      private readonly ILogger _logger;
      private Timer _timer;

      public TimerService (ILogger<TimerService> logger)

      _logger = logger;


      public Task StartAsync(CancellationToken cancellationToken)

      _logger.LogInformation("Timed Background Service is starting.");

      _timer = new Timer(DoWork, null, TimeSpan.Zero,
      TimeSpan.FromSeconds(1));

      return Task.CompletedTask;


      private async void DoWork(object state)

      //Do your stuff here
      await Task.Delay(50);
      _logger.LogInformation("Timed Background Service is executing.");


      public Task StopAsync(CancellationToken cancellationToken)

      _logger.LogInformation("Timed Background Service is stopping.");

      _timer?.Change(Timeout.Infinite, 0);

      return Task.CompletedTask;


      public void Dispose()

      _timer?.Dispose();





      Middleware pipeline



      started using Configure



       public async Task Invoke(HttpContext context, ILogger<APIKeyHandler> logger, IConfiguration configuration)

      _logger = logger;

      bool KeyInHeader = context.Request.Headers.ContainsKey("Key");

      if (KeyInHeader)

      if (context.Request.Headers["Key"] = *!!VALUE COLLECTED USING THE TimerService*!!)

      context.Response.StatusCode = (int)HttpStatusCode.NoContent;
      await context.Response.WriteAsync($"Executed");





      There is currently no way to get the values from the TimerService. I would like to be able to reference Timerservice.LatestValue or something. If this is not the way to I would love to get some directions.










      share|improve this question














      I used this example to create a timed background task. Using this background task I have a value that is updated every x seconds, which works fine.



      However, I want to be able to use this value in my middleware pipeline. How is this achieved? Can I used someting like a global variable or reference the HostedService in some way?



      Timed background service



      Started using ConfigureServices
      services.AddHostedService<<>>();




      public class TimerService : IHostedService, IDisposable

      private readonly ILogger _logger;
      private Timer _timer;

      public TimerService (ILogger<TimerService> logger)

      _logger = logger;


      public Task StartAsync(CancellationToken cancellationToken)

      _logger.LogInformation("Timed Background Service is starting.");

      _timer = new Timer(DoWork, null, TimeSpan.Zero,
      TimeSpan.FromSeconds(1));

      return Task.CompletedTask;


      private async void DoWork(object state)

      //Do your stuff here
      await Task.Delay(50);
      _logger.LogInformation("Timed Background Service is executing.");


      public Task StopAsync(CancellationToken cancellationToken)

      _logger.LogInformation("Timed Background Service is stopping.");

      _timer?.Change(Timeout.Infinite, 0);

      return Task.CompletedTask;


      public void Dispose()

      _timer?.Dispose();





      Middleware pipeline



      started using Configure



       public async Task Invoke(HttpContext context, ILogger<APIKeyHandler> logger, IConfiguration configuration)

      _logger = logger;

      bool KeyInHeader = context.Request.Headers.ContainsKey("Key");

      if (KeyInHeader)

      if (context.Request.Headers["Key"] = *!!VALUE COLLECTED USING THE TimerService*!!)

      context.Response.StatusCode = (int)HttpStatusCode.NoContent;
      await context.Response.WriteAsync($"Executed");





      There is currently no way to get the values from the TimerService. I would like to be able to reference Timerservice.LatestValue or something. If this is not the way to I would love to get some directions.







      asp.net-core-2.1






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 19:44









      user158936user158936

      11 bronze badge




      11 bronze badge

























          0






          active

          oldest

          votes














          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );














          draft saved

          draft discarded
















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405724%2fhow-make-data-from-a-hostedservice-available-in-my-pipeline%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55405724%2fhow-make-data-from-a-hostedservice-available-in-my-pipeline%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript