I'm new to Onion Architecture and am trying to apply it in an ASP.NET project. I'm currently implementing ASP.NET Identity and want to use its UserManager
class to store users.
From what I understood from Onion Architecture is that I should create an interface in the domain layer that can be used to wrap the UserManager
.
public interface IUserManager
{
public Task CreateAsync(string username, string password);
}
And in the infrastructure layer I would then implement my own UserManager
that wraps the ASP.NET Identity UserManager
.
using Microsoft.AspNetCore.Identity;
public class MyUserManager : IUserManager
{
private readonly UserManager<IdentityUser> _userManager;
public UserManager(UserManager<IdentityUser> userManager)
{
_userManager = userManager;
}
public async Task CreateAsync(string username, string password)
{
var user = new IdentityUser { UserName = username };
await _userManager.CreateAsync(user, password);
}
}
Problem
My issue with this is that I would also like to return possible errors from UserManager.CreateAsync(...)
instead of having a void
return type. Looking something like this:
public class IdentityResult
{
public bool Succeeded { get; set; }
public IEnumerable<string> Errors { get; set; } // Some Error type instead of a string would be better
}
I'd have to define this DTO in the domain layer since they have to be part of the IUserManager
interface, but I'm not sure if that's the right approach. From the open source projects that I've found I see none of them using DTOs in the domain layer and people seem to be saying that DTOs are generally an application concern, but I could just be waaay overthinking it. Maybe I'm already taking the wrong approach with the way I'm currently doing it?