giorgos07/Daarto

IdentityBuilderExtensions.AddStores ignores AddUsersTable option if implementation is UserOnlyStore

Opened this issue · 0 comments

DapperStoreOptionsExtension adds the scoped IService

options.Services.AddScoped(typeof(IUsersTable<,,,,,>).MakeGeneric....

However if a roleType is not provided, DI looks for an implementation of IUsersOnlyTable<,,,,>. There are 2 possible solutions depending on what you want:

  1. add a scoped service for both IUsersTable and IUsersOnlyTable in the AddUsersTable method of DapperStoreOptionsExtension
  2. Alter the IServicesCollection to replace the IService for IUsersTable with 1 for the service IUsersOnlyTable and the same implementationType, along the lines of:
var usersTableServiceType = typeof(IUsersTable<,,,,,>).MakeGenericType(userType, keyType, userClaimType, userRoleType, userLoginType, userTokenType);
if (roleType != null) {
   ...
	services.TryAddScoped(
		usersTableServiceType,
		typeof(UsersTable<,,,,,>).MakeGenericType(userType, keyType, userClaimType, userRoleType, userLoginType, userTokenType)
	);
	....
} else {
	var serviceType = services.FirstOrDefault(s => s.ServiceType == usersTableServiceType);
	usersTableServiceType = typeof(IUsersOnlyTable<,,,,>).MakeGenericType(userType, keyType, userClaimType, userLoginType, userTokenType);
	if (serviceType == null)
	{
		services.TryAddScoped(usersTableServiceType, typeof(UsersTable<,,,,,>).MakeGenericType(userType, keyType, userClaimType, userRoleType, userLoginType, userTokenType));
	}
	else
	{
		services.Remove(serviceType);
		services.TryAddScoped(usersTableServiceType, serviceType.ImplementationType);
	}
	userStoreType = typeof(UserOnlyStore<,,,,>).MakeGenericType(userType, keyType, userClaimType, userLoginType, userTokenType);
}