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...
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...