Replacement for IRegisteredObject in ASP.NET 5?

I am trying to create a simple ASP.NET 5 application with SignalR that should regularly send messages to clients (for example, implement a dashboard with the values ​​passed from the server to the browser).

I studied some posts like http://arulselvan.net/realtime-dashboard-asp-net-signalr-angularjs-d3js/ or http://henriquat.re/server-integration/signalr/integrateWithSignalRHubs.html . They recommend using a timer in a class that implements IRegisteredObject from the System.Web.Hosting .

However, I seem to be unable to find the namespace in which IRegisteredObject lives in ASP.NET 5. System.Web no longer exists in ASP.NET 5. I could not find information about this on the Internet. What will replace it in ASP.NET 5?

UPDATE

I am trying to execute the following solution:

  • create a timer encapsulating service

  • register it in Startup.cs as a singleton service, for example

     public class Ticker { Timer timer = new Timer(1000); public Ticker() { timer.Elapsed += Timer_Elapsed; timer.Start(); } private void Timer_Elapsed(object sender, ElapsedEventArgs e) { // do something } } 

In Startup.cs

 public void ConfigureServices(IServiceCollection services) { // ... Ticker ticker = new Ticker(); ServiceDescriptor sd = new ServiceDescriptor(typeof(Ticker), ticker); services.Add(sd); // ... } 

How about this approach?

+5
source share
1 answer

IRegisteredObject basically just provides a way to notify the implementation class of an impending death as soon as your instance is registered with HostingEnvironment.RegisterObject .

There is no need to implement any interface in the .net kernel. The corresponding method is HostingEnvironment.RegisterObject IApplicationLifetime.ApplicationStopping . Register .

In your IoC application, make sure you use the IApplicationLifetime dependency for the object or job manager or anything to be able to register or link it in some way in Startup.cs Configure , where you can access the IoC structure instance of this interface:

 public void Configure(IApplicationBuilder app, IApplicationLifetime applicationLifetime) { // Pipeline setup code ... applicationLifetime.ApplicationStopping.Register(() => { // notify long-running tasks of pending doom }); } 
+1
source

Source: https://habr.com/ru/post/1247385/


All Articles