Registering Handlers that are not public #1035
-
Hey, guys! Context: A modular monolith .net 8 app where each module has following class libraries:
In the Web Api project i am trying to register Wolverine Handlers. I currently only changed the login commandHandler to be an IWolverineHandler so I can play around with it. I did read from the Wolverine documentation that by default it looks for public concrete classes, but I also found the .IsNotPublic specification, so I am a little confused. Part of Program.cs code: builder.Host.UseWolverine(opts =>
{
opts.Discovery
.DisableConventionalDiscovery()
.CustomizeHandlerDiscovery(c =>
{
c.Includes.IsNotPublic(); //Here I specify it to look for non public classes
c.Includes.WithNameSuffix("Handler");
c.Includes.Implements<IWolverineHandler>(); //Here I specify it to look for handlers that implement this
List<Assembly> assemblies =
[
..IdentityDomainServiceExtensionMethods.GetIdentityAssemblies()
];
c.Find(assemblies);
})
.CustomizeMessageDiscovery(c =>
{
c.Includes.WithNameSuffix("Command");
c.Includes.WithNameSuffix("Query");
c.Includes.WithNameSuffix("Event");
});
opts.CodeGeneration.TypeLoadMode = TypeLoadMode.Auto;
opts.UseFluentValidation();
opts.LocalQueue("in-process-queue");
opts.LogMessageStarting(LogLevel.Information);
}); The definition of the method that returns the Assemblies of interest public static List<Assembly> GetIdentityAssemblies()
{
return [typeof(LoginCommandHandler).Assembly, typeof(LoginCommand).Assembly];
} The Login command message: namespace Erp.IdentityModule.Contracts.Commands;
public record LoginCommand(string Email, string Password); The Login command handler: using System.Runtime.CompilerServices;
using System.Security.Claims;
using Ardalis.GuardClauses;
using Ardalis.Result;
using Erp.IdentityModule.Contracts.Commands;
using Erp.IdentityModule.Contracts.Dtos;
using Erp.IdentityModule.Domain.Entities;
using Erp.IdentityModule.Domain.Infrastructure.Repositories.Interfaces;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Identity;
using Wolverine;
namespace Erp.IdentityModule.Domain.Integrations.Commands;
internal class LoginCommandHandler : IWolverineHandler
{
private readonly UserManager<AppUser> _userManager;
private readonly SignInManager<AppUser> _signInManager;
private readonly IAppRoleClaimRepository _roleClaimRepository;
private readonly ITenantDetailsRepository _tenantRepository;
internal LoginCommandHandler(
UserManager<AppUser> userManager,
SignInManager<AppUser> signInManager,
ITenantDetailsRepository tenantRepository,
IAppRoleClaimRepository roleClaimRepository)
{
_userManager = userManager;
_signInManager = signInManager;
_tenantRepository = tenantRepository;
_roleClaimRepository = roleClaimRepository;
}
public async Task<Result<(ClaimsPrincipal, LoginResponse)>> Handle(LoginCommand request)
{
//... code logic
return Result<(ClaimsPrincipal, LoginResponse)>.Success((claimsPrincipal, loginResponse));
}
} Whatever I have tried it still throws an exception like:
So please help me with my confusion! Is there something that I can do to register non public Handlers? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@gabrielciucaalbu Sorry, I honestly didn't even realize that GitHub discussions are enabled. Sorry, no, Wolverine -- as the documentation does explain -- can only work with public handler types due to its internal model. |
Beta Was this translation helpful? Give feedback.
@gabrielciucaalbu Sorry, I honestly didn't even realize that GitHub discussions are enabled. Sorry, no, Wolverine -- as the documentation does explain -- can only work with public handler types due to its internal model.