2024-04-18 01:44:37 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
namespace Wino.Activation;
|
|
|
|
|
|
|
|
|
|
|
|
public abstract class ActivationHandler
|
2025-02-16 11:35:43 +01:00
|
|
|
|
{
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public abstract bool CanHandle(object args);
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public abstract Task HandleAsync(object args);
|
|
|
|
|
|
}
|
2024-04-18 01:44:37 +02:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
// Extend this class to implement new ActivationHandlers
|
|
|
|
|
|
public abstract class ActivationHandler<T> : ActivationHandler
|
|
|
|
|
|
where T : class
|
|
|
|
|
|
{
|
|
|
|
|
|
// Override this method to add the activation logic in your activation handler
|
|
|
|
|
|
protected abstract Task HandleInternalAsync(T args);
|
2025-02-16 11:43:30 +01:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public override async Task HandleAsync(object args)
|
|
|
|
|
|
{
|
|
|
|
|
|
await HandleInternalAsync(args as T);
|
|
|
|
|
|
}
|
2025-02-16 11:43:30 +01:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
public override bool CanHandle(object args)
|
|
|
|
|
|
{
|
|
|
|
|
|
// CanHandle checks the args is of type you have configured
|
|
|
|
|
|
return args is T && CanHandleInternal(args as T);
|
|
|
|
|
|
}
|
2025-02-16 11:43:30 +01:00
|
|
|
|
|
2025-02-16 11:54:23 +01:00
|
|
|
|
// You can override this method to add extra validation on activation args
|
|
|
|
|
|
// to determine if your ActivationHandler should handle this activation args
|
|
|
|
|
|
protected virtual bool CanHandleInternal(T args)
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
2024-04-18 01:44:37 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|