You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment the DI registration for INotificationHandlers registers them all via SP.GetRequiredService.
I have the use case that in some cases (tests or certain features are disabled) I'd like to remove certain NotificationHandlers from the global list, as they might have unintended side effects for tests or a simply disabled.
Let's assume I have a notification MyNotification and an implementation handler MyNotificationHandler, which I want to remove.
Conceptionally the code looks like this for a ServiceDescription registration:
varsd=newServiceDescriptor(typeof(INotificationHandler<MyNotification>), p =>p.GetRequiredService<MyNotificationHandler>(),ServiceLifetime.Singleton);
due to the fact how the registration works, the functor is actually Func<IServiceProvider, object> making it impossible to obtain the real implementation type via reflection without reverting to tricks like IL inspection.
I propose to change the registration to something like:
The above code results in a delegate target which looks like this: <>c__2<MyNotificationHandler> and this allows us to identify the correct handler to remove.
The text was updated successfully, but these errors were encountered:
At the moment the DI registration for INotificationHandlers registers them all via
SP.GetRequiredService
.I have the use case that in some cases (tests or certain features are disabled) I'd like to remove certain NotificationHandlers from the global list, as they might have unintended side effects for tests or a simply disabled.
Let's assume I have a notification
MyNotification
and an implementation handlerMyNotificationHandler
, which I want to remove.Conceptionally the code looks like this for a ServiceDescription registration:
due to the fact how the registration works, the functor is actually
Func<IServiceProvider, object>
making it impossible to obtain the real implementation type via reflection without reverting to tricks like IL inspection.I propose to change the registration to something like:
The above code results in a delegate target which looks like this:
<>c__2<MyNotificationHandler>
and this allows us to identify the correct handler to remove.The text was updated successfully, but these errors were encountered: