How to preserve the value of a variable between Rest requests

  • Thread starter Thread starter Ramya gollapudi
  • Start date Start date
R

Ramya gollapudi

Guest
For each HandleEvent the _newProduct would be set to true, but while I get HandleAnotherEvent the value of this _newProduct is becoming false. How to preserve this? I dont want to use static variable? Is there any other way?


public sealed class ProductNotificationHandler : INotificationHandler<HandleEvent>, INotificationHandler<HandleAnotherEvent>

{

private bool _newProduct = false;

public async Task Handle(HandleEvent eventNotification, CancellationToken cancellationToken)
{

_newProduct = eventNotification.NewProduct

}

public async Task Handle(HandleAnotherEvent eventNotification, CancellationToken cancellationToken)
{

if(_newProduct){ } //do logic

}


}


public class PublishNotification() : IPublishNotification

{

_mediator.Publish(new HandleEvent{ NewProduct= true;}, CancellationToken.None);

}

Statup.cs

{

services.AddSingleton<ProductNotificationHandler>();

builder.RegisterType<PublishNotification>().As<PublishNotification>().SingleInstance();

}

Continue reading...
 

Similar threads

I
Replies
0
Views
109
IndigoMontoya
I
S
Replies
0
Views
90
Stan Huang at Taiwan
S
Back
Top