I have a permanent object with some event. Is it possible to make this object active throughout the life of the application. Suppose that an object and an event look like this:
var myObject = new MyObject(); myObject.CustomEvent += _myEvent; private void _myEvent(object sender, CustomEvent e) { using (var db = new DbContext()) { db.MyEntity.Add(e.Property); db.SaveChanges(); } } I tried to put it in the Startup class and the Application_Start method. Also tried to add to HostingEnvironment.QueueBackgroundWorkItem . As I understand it, the object is destroyed everywhere and the event does not occur. Thanks for the help!