Coder Social home page Coder Social logo

alexandre-spieser / aspnetcore.identity.mongodbcore Goto Github PK

View Code? Open in Web Editor NEW
249.0 13.0 70.0 1.25 MB

A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.2. Allows you to use MongoDb instead of SQL server with Microsoft.AspNetCore.Identity 2.2. (not Identity 3.0)

License: MIT License

C# 99.98% PowerShell 0.02%
mongodb identity store asp-net-core aspnetcore userstore rolestore

aspnetcore.identity.mongodbcore's Introduction

AspNetCore.Identity.MongoDbCore

A MongoDb UserStore and RoleStore adapter for Microsoft.AspNetCore.Identity 2.0 and 3.1. Allows you to use MongoDb instead of SQL server with Microsoft.AspNetCore.Identity 2.0 and 3.1.

Covered by 737 integration tests and unit tests from the modified Microsoft.AspNetCore.Identity.EntityFrameworkCore.Test test suite.

Supports both netstandard2.1 and netcoreapp3.1.

Available as a Nuget package : https://www.nuget.org/packages/AspNetCore.Identity.MongoDbCore/

Install-Package AspNetCore.Identity.MongoDbCore

Support This Project

If you have found this project helpful, either as a library that you use or as a learning tool, please consider buying Alex a coffee: Buy Me A Coffee

User and Role Entities

Your user and role entities must inherit from MongoIdentityUser<TKey> and MongoIdentityRole<TKey> in a way similar to the IdentityUser<TKey> and the IdentityRole<TKey> in Microsoft.AspNetCore.Identity, where TKey is the type of the primary key of your document.

Here is an example:

public class ApplicationUser : MongoIdentityUser<Guid>
{
	public ApplicationUser() : base()
	{
	}

	public ApplicationUser(string userName, string email) : base(userName, email)
	{
	}
}

public class ApplicationRole : MongoIdentityRole<Guid>
{
	public ApplicationRole() : base()
	{
	}

	public ApplicationRole(string roleName) : base(roleName)
	{
	}
}	

Id Fields

The Id field is automatically set at instantiation, this also applies to users inheriting from MongoIdentityUser<int>, where a random integer is assigned to the Id. It is however not advised to rely on such random mechanism to set the primary key of your document. Using documents inheriting from MongoIdentityRole and MongoIdentityUser, which both use the Guid type for primary keys, is recommended. MongoDB ObjectIds can optionally be used in lieu of GUIDs by passing a key type of MongoDB.Bson.ObjectId, e.g. public class ApplicationUser : MongoIdentityUser<ObjectId>.

Collection Names

MongoDB collection names are set to the plural camel case version of the entity class name, e.g. ApplicationUser becomes applicationUsers. To override this behavior apply the CollectionName attribute from the MongoDbGenericRepository nuget package:

using MongoDbGenericRepository.Attributes;

namespace App.Entities
{
    // Name this collection Users
    [CollectionName("Users")]
    public class ApplicationUser : MongoIdentityUser<Guid>
    {
	...

Configuration

To add the stores, you can use the IdentityBuilder extension like so:

services.AddIdentity<ApplicationUser, ApplicationRole>()
	.AddMongoDbStores<ApplicationUser, ApplicationRole, Guid>
	(
		"mongodb://localhost:27017",
		"MongoDbTests"
	)
	.AddDefaultTokenProviders();

It is also possible to share a common IMongoDbContext across your services (requires https://www.nuget.org/packages/MongoDbGenericRepository/):

var mongoDbContext = new MongoDbContext("mongodb://localhost:27017", "MongoDbTests");
services.AddIdentity<ApplicationUser, ApplicationRole>()
	.AddMongoDbStores<IMongoDbContext>(mongoDbContext)
	.AddDefaultTokenProviders();
// Use the mongoDbContext for other things.

You can also use the more explicit type declaration:

var mongoDbContext = new MongoDbContext("mongodb://localhost:27017", "MongoDbTests");
services.AddIdentity<ApplicationUser, ApplicationRole>()
	.AddMongoDbStores<ApplicationUser, ApplicationRole, Guid>(mongoDbContext)
	.AddDefaultTokenProviders();
// Use the mongoDbContext for other things.

Alternatively a full configuration can be done by populating a MongoDbIdentityConfiguration object, which can have an IdentityOptionsAction property set to an action you want to perform against the IdentityOptions (Action<IdentityOptions>).

The MongoDbSettings object is used to set MongoDb Settings using the ConnectionString and the DatabaseName properties.

The MongoDb connection is managed using the mongodb-generic-repository, where a repository inheriting IBaseMongoRepository is registered as a singleton. Look at the ServiceCollectionExtension.cs file for more details.

var mongoDbIdentityConfiguration = new MongoDbIdentityConfiguration
{
	MongoDbSettings = new MongoDbSettings
	{
		ConnectionString = "mongodb://localhost:27017",
		DatabaseName = "MongoDbTests"
	},
	IdentityOptionsAction = options =>
	{
		options.Password.RequireDigit = false;
		options.Password.RequiredLength = 8;
		options.Password.RequireNonAlphanumeric = false;
		options.Password.RequireUppercase = false;
		options.Password.RequireLowercase = false;

		// Lockout settings
		options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
		options.Lockout.MaxFailedAccessAttempts = 10;

		// ApplicationUser settings
		options.User.RequireUniqueEmail = true;
		options.User.AllowedUserNameCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@.-_";
	}
};
services.ConfigureMongoDbIdentity<ApplicationUser, ApplicationRole, Guid>(mongoDbIdentityConfiguration)
        .AddDefaultTokenProviders();

Running the tests

To run the tests, you need a local MongoDb server in default configuration (listening to localhost:27017). Create a database named MongoDbTests for the tests to run.

Author

Alexandre Spieser

License

AspNetCore.Identity.MongoDbCore is under MIT license - http://www.opensource.org/licenses/mit-license.php

The MIT License (MIT)

Copyright (c) 2016-2021 Alexandre Spieser

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Copyright

Copyright © 2021

aspnetcore.identity.mongodbcore's People

Contributors

alexandre-spieser avatar d-barker avatar jhadwen avatar joshuadavidson avatar mjebrahimi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aspnetcore.identity.mongodbcore's Issues

how can I user this in asp.net core 3.0 ?

asp.net core 3.0 default code like this:

services.AddIdentityServer() .AddApiAuthorization<ApplicationUser, ApplicationDbContext>();

it use identityserver to provider jwt Authorization, Can you update this package ?

Can I expire the session using your example?

Hi @alexandre-spieser ,

I took this package and was running through your example as well as the standard IdentityServer4 Quickstart one https://github.com/IdentityServer/IdentityServer4.Quickstart.UI and my question is regarding logging out / expiring tokens. Is it possible to perform that via the sign in manager you use in your example? At the moment I wasn't able to perform a log in establishing how long the token would be valid or whether I want to be remembered for, let's say one day. Also, and I'm not sure if that could be related, when I clone tabs and perform a log out, the other tab keeps being logged in and the token/session seems to be still active.

I have posted a more detailed question in StackOverflow: https://stackoverflow.com/questions/55168608/sign-out-from-all-sessions-identityserver4 but I would appreciate if you could tell me whether you came across that issue before or know of any example I could have a look at.

Thanks!

Element 'Principal' does not match any field or property of class Microsoft.AspNetCore.Identity.UserLoginInfo.

Hi there,

I'm getting this exception on several methods when I'm trying to check a user exists (FindByEmail, FindByUsername) before creating a new one and on creating a new user. I don't think I can find a way around this.

From what I can tell, this is coming from trying to serialise the Logins property of MongoIdentityUser, of which the Principal property is empty, after adding a login to the user.

This is happening after the user is initially created. I'm able to create a user, add logins, and sign in to my application on the first attempt.

Any help would be appreciated!

UserManager filtering users not fully working

Hi @alexandre-spieser ,

Have you come across this issue before? I have a standard configuration of the MongoDbCore package which I have been using for a while. All works fine and today I wanted to filter the list of users based on a role. Looking around I found you can directly use the manager and apply some LINQ expressions like this:

applicationUsers = _userManager.Users
                                                      .Where(u => u.Roles.All(r => r != adminRole.Id))
                                                      .Skip((userSearch.Page - 1) * userSearch.PageSize)
                                                      .Take(userSearch.PageSize)
                                                      .ToList();

The thing is though, I got the following error:

System.ArgumentException: 'Unsupported filter: All({document}{Roles}.Where(({document} != 5724fdf9-83e3-4331-9f15-c9de9b243c09))).'

So I'm not sure whether there is something I'm missing in terms of configuration or setup, but to get this working, I have to transform the Users property ToList and then apply the LINQ filter. I'm assuming that's not entirely right?

For reference I'm using v1.1.1 of the package

Update for Blazor?

This looks like a great project and that you recently provided support for .NET Core 3.1. I'm new to ASP.NET and would like to use this with a Blazor (server) app. But since I'm so new to ASP.NET and Blazor, I can't really figure how to start using this Identity service with Blazor. I'm sure it would be really simple for you. Would you be willing to update your test site with a Blazor version?

Keep up the good work,
Chris

Is it possible to use with older version of Asp.net Indentity versions below 2.0?

I can see that the Asp.net Indentity implementation in this wil have nomalizedemail and normalizedusername etc. I have an existing app and I want to use this package against the existing database. Is it possible to authenticate against the existing users in the database which was created with older version of aspnet identity?

Update Readme

Hello there,

Once again, thanks for teh great work and the awesome library!

After the latest release 3.1, could you update the readme in order to know whether we have an equivalent for AddDefaultTokenProviders(). Taking a look at the release notes is not very clear to me if we still have to call the method somehow.

Thanks!

_userManager.IsInRoleAsync is always false

Calling the user manager is in role always returns false no matter what.

Here is how I instantiate the user manager and the role manager:

public AdministratorController(IUrlHelper urlHelper, UserManager<AppUser> userManager, RoleManager<MongoRole> roleManager) : base(urlHelper) { _userManager = userManager; _roleManager = roleManager; }

Here is how I add a user to a role (it works well):

var res1 = await _userManager.AddClaimAsync(user, new Claim(ClaimTypes.Role, roleAddModel.RoleName)); var res = await _userManager.AddToRoleAsync(user, roleAddModel.RoleName);

And after adding a user to a role then going to the database to test if this user exists, it works well.
But, when I use this method to test if the user was assigned a specific role, I get a "FALSE" response all the time:

var r = await _userManager.IsInRoleAsync(user, roleAddModel.RoleId);

Or even when I try to remove a user from a role, I always get an error stating the user is not assigned to the role. Whereas, the user is assigned and I can see it in the database.

var res = await _userManager.RemoveFromRoleAsync(user, roleAddModel.RoleName);

Can someone help ? please

Update (your own) MongoDbGenericRepository nuget to latest 1.4.7

Hi, when I update the nuget MongoDbGenericRepository to the latest 1.4.7 version, an exception occurs e.g. when I call FindByEmailAsync in the UserManager. The exception says that requested GetOneAsync method is not found in IBaseReadOnlyRepository interface. Please, update the reference to the MongoDbGenericRepository so it is up to date.

Rename Collections

Currently, the collection names are based on the classes, e.g. mongoIdentityRoles for Roles. Is there a way to override the naming of the collections?

Duplicate username and email inserted

Steps to reproduce:

  • Set user to the same username and/or email
  • Configure Services with unique email:

services.AddIdentity<ApplicationUser, ApplicationRole>(options => { options.User = new UserOptions { RequireUniqueEmail = true }; })

var resultTask1 = userManager.CreateAsync(user1, password);
var resultTask2 = userManager.CreateAsync(user2, password);
await Task.WhenAll(resultTask1, resultTask2);

Result:
2 records are inserted into Mongo

Expected result
1 record should be inserted in Mongo

Sign the assembly

When building code using AspNetCore.Identity.MongoDbCore, I get the following warning:

CS8002	Referenced assembly 'AspNetCore.Identity.MongoDbCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' does not have a strong name.

Please sign it. TIA!

Deleting a role doesn't remove it from users

If a user is linked to a role (it's in his Roles array) and I delete that role from the roles collection using RoleManager.DeleteAsync(), the link remains with the user, which causes integrity problems later on.

Is this a Microsoft Identity problem or yours?

Rename/Remove properties

Hi !
I didn`t want to store some of from those properties like PhoneNumber and I want also to rename properties in mongo to lowercase.
Is there a method to do that?

I tried to override them and use annotation BsonIgnore or BsonElement but not works maybe it was a dumb idea.

Then I tried to create class mapper conform : https://mongodb-documentation.readthedocs.io/en/latest/ecosystem/tutorial/serialize-documents-with-the-csharp-driver.html
but I got NullRefferenceExeption maybe I done something wrong.

Could you help me please?

IDictionary<string, string> Properties missing on MongoClaim

Description
System.Security.Claims.Claim contains a property named Properties of type IDictionary<string,string>.
When trying to add a new System.Security.Claims.Claim to a Role , any KeyValuePair<string,string> that was added to Claim->Properties is discarded since no mapping property exists on MongoClaim.
RoleManager<TRole>.AddClaimAsync(TRole, System.Security.Claims.Claim)

 var claimToAdd = new Claim("Type", "Value");
 claimToAdd.Properties.Add("Key", "Value");
 await roleManager.AddClaimAsync(role, claimToAdd);

Expected
Properties dictionary should be persisted as well.

Actual
Properties dictionary is discarded.

Running the sample in VS

I spent some hours trying to figure out how to run the sample in VS 2019 16.4.5 and then 16.5.4 (latest). I had SSL issues ("This site can’t provide a secure connection") followed by IIS issues ("Unable to connect to web server 'IIS Express').

Finally, I saw that a VSCode folder was checked in. So I ran the sample in VSCode and everything just worked. I never got it running in VS.

Is anyone else having issues running this in VS?

Stores use a static IMongoRepository

Hi,

If a store is used (User/Role etc) then the IMongoRepository repository is assigned to a static variable in "lazy assignment" pattern. Once that assignment is made every future instance of the store (e.g. in a brand new WebHost) will have the same initial database connection, regardless of what context is passed into the initializer (in the Startup). Basically meaning that it is impossible to switch connections, or create multiple webhosts with different connections.

Solution seems relatively trivial to change MongoRepository (and Context because the same paradigm) to member variables.

private readonly object _mongoRepositoryInitializationLock = new object(); private IMongoRepository _mongoRepository; private IMongoRepository MongoRepository { get { // double checked locking to prevent race to initialize the repository in multithreaded environment. if (_mongoRepository == null) { lock (_mongoRepositoryInitializationLock) { if (_mongoRepository == null) { _mongoRepository = new MongoRepository(Context); } } } return _mongoRepository; } }

I'm not even sure that MongoRepository is that expensive to create to warrant this pattern anyway.

Thanks

James

SignInManager.IsSignedIn method is always false.

Hi Alexandre, I wanted to congratulate you because it is a nice job.

I got your code and goes run, its compilies correctely, created the base on mongo and registered a user, but after the login its behavior is like I never did the login before.

Could you help me with that, nothing was modified in your code.

image

Issues with the 3.1.0 version

  1. Please align nuspec and csproj dependencies verisons: downgrage csproj's ones to at least 3.1.8 (or better 3.1.0 or 3.1.1). Otherwise my project doesn't complile at all. Then don't worry - it's my duty to maintain actual runtime versions.
  2. Please remove Microsoft.VisualStudio.Web.BrowserLink dependency - it's irrelevant here.

No service for type 'UserManager<IdentityUser>' has been registered.

I have the sample running successfully in VS 2019 (with the following lines removed):

    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
    <AspNetCoreModuleName>AspNetCoreModule</AspNetCoreModuleName>

But if I create a new ASP.NET Core MVC App and add the nuget package, I get the error:

InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered.

In an effort to figure it out, I

  • Copied the PackageReferences in the CSPROJ file to mine
  • Copied the Configure and ConfigureServices methods to mine
  • Copied over the appsettings and run the new app

But I keep getting the error:

InvalidOperationException: No service for type 'Microsoft.AspNetCore.Identity.UserManager`1[Microsoft.AspNetCore.Identity.IdentityUser]' has been registered.

Any ideas why this is failing for my new app?

Issue when using UserStore in my Service Layer.

Thank you for this awesome library, to integrate .net identity with Mongo DB.

Have worked well so far, except for this issue I am facing with using userStore instead of userManager.

So I need to fetch user by its Id, since its needed in service layer, I am trying to userStore and not manager.

But when I try to inject UserStore...it complains that it can not convert from User to User.

I have seen UserStore class and it loosk like its implemented only for string type , not able to figure out why its complaining. I thought it should be generic instead of just string.

Suggestion: ObjectId

Hi there

How about using the MongoDB native type ObjectId as identifier on Users and Roles? In order to support that type, the following changes has to be done:

MongoIdentityRole.cs line 84
case "ObjectId":
Id = (TKey)(object)ObjectId.GenerateNewId();
break;

MongoIdentityUser.cs line 391
case "ObjectId":
Id = (TKey)(object)ObjectId.GenerateNewId();
break;

Use of IMongoClient instead of MongoClient

I have an application that uses a custom IMongoClient implementation to support Polly for retries. Any thoughts on changing the AddMongoDbStores method to accept an IMongoClient instead of a MongoClient? This wouldn't be a breaking change since MongoClient already implements IMongoClient and would give the flexibility for other implementations and mock testing.

The other change I'd like to discuss (or maybe instead of the one above) is to provide an overload of AddMongoDbStores that accepts a Func<IMongoClient> parameter that will be called the first time it needs the IMongoClient. The reason for this is that I need to access an IServiceProvider to get the IMongoClient since it has injection dependencies and doing it against the IServiceCollection is too early in the process.

explanation services.AddIdentity multi roles

Hi,
we have implemented in our solution, but we must have a role chosen if a user has more than one. when the user chooses the role we first retrieve the user we delete the roles except the selected one and sign in. if we stay on the same page for more than a few minutes (about 20/30) we update the user has tuttle role and not just the one selected.
Any Ideas?
Regards
Stefano

MongoDB connection string with options

My mongodb connection string looks like:
"mongodb://user:password@localhost:27017/Identity?ssl=true&authSource=admin"
when I break it to MongoDbSettings as

"MongoDbSettings": { "ConnectionString": "mongodb://user:password@localhost:27017/", "DatabaseName": "Identity?ssl=true&authSource=admin" }

I can't connect to the database, am I doing something wrong?

Not able to update user.

Can you share an example of how to update User.

I am using this method to update user.

var result = await UserManager.UpdateAsync(AppUser).ConfigureAwait(false);

Do I need to implment customUserStore or can use existing mongoUserStore to update user?

CollectionNames While Using Generics

I am using the models which are available out of the box and using MongoIdentityUser<string> instead of plain MongoIdentityUser. This creates a collection named mongoIdentityUser`1s when I insert a new user.

The collection name is fine when I use the non-generic MongoIdentityUser

Another issue is that userstore.FindByNameAsync does not return the user

MongoIdentityUser user = new MongoIdentityUser("Test", "[email protected]");
IdentityResult r =  _userStore.CreateAsync(user, new System.Threading.CancellationToken()).Result;
userStore.FindByNameAsync(model.Username, default(CancellationToken)).Result`

The user is created successfully in the database but it does not return the freshly created user because it is comparing with NormalizedUserName.

My services set up in Startup.ConfigureServices is

MongoDbContext m = new MongoDbContext(Configuration.GetConnectionString("mca2"));
            services.AddIdentity<MongoIdentityUser, MongoIdentityRole>()
            .AddMongoDbStores<MongoIdentityUser, MongoIdentityRole, Guid>(m)
            .AddSignInManager<SignInManager<MongoIdentityUser>>()
    .AddDefaultTokenProviders();

System.TypeLoadException when using with GenericRepository

Hello,

When used with generic repository
System.TypeLoadException: 'Could not load type 'MongoDbGenericRepository.IMongoDbCollectionIndexRepository' from assembly 'MongoDbGenericRepository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.'

error occurs on:
services.AddIdentity<ApplicationUser, ApplicationRole>() .AddMongoDbStores<ApplicationUser, ApplicationRole, Guid>(taskDbContext) .AddDefaultTokenProviders();

It is probably because of this package's internally dependency on IMongoDbCollectionIndexRepository while GenericRepository has the same interface with different assembly version

Basic tutorial for Blazor and dotnet 5

Could you please prepare vary basic tutorial for using this lib with Blazor and dotnet 5.0?
I mean basic login, registration and logout functionalities only.

ASP.NET Core Razor Pages 3.1 - Register and Login Links are not working

Hello,

I need to setup a MongoDB Identity provider that works with Google Authentication. Firstly, after setting up MongoDbCore by using the MVC sample, the application runs up but the Register and Login links are not functional anymore. Since Register and Login code is not anymore visible by default within the project structure, it makes difficult debugging.

At best, would be nice if there is an updated sample for ASP.NET Core 3.1 Razor Pages.
Am I missing some new settings in Startup.cs or is there any issue with ASP.NET Core 3.1?

Window 10, 2004, Build: 19041.450
Visual Studio 2019

Thank you, regards
Constantin

Screenshot_45

Publish next NuGet version

Hello there! Recently we have run into a similar issue than #51, but then noticed that the commit that fixes it is not yet published to NuGet even after some time.

Would it be possible to make this happen?

Much thanks!

Injecting SignInManager through DI causing issues when trying to resolve

Using version 3.1.1:

ConfigureServices():

services.ConfigureMongoDbIdentity<ApplicationUser, ApplicationRole, Guid>(new MongoDbIdentityConfiguration {
    MongoDbSettings = new MongoDbSettings {
        ConnectionString = this._configuration.GetConnectionString("DatabaseConnectionString"),
        DatabaseName = "DatabaseName"
    },
    IdentityOptionsAction = options => {
        // ApplicationUser settings
        options.User.RequireUniqueEmail = true;
    }
});

services.AddScoped<IAppUserManager, AppUserManager>();

And trying to inject SignInManager like so:

public AppUserManager(IConfiguration configuration, ILogger<AppUserManager> logger,
    UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager,
    IMapper mapper) {
    this._configuration = configuration;
    this._logger = logger;
    this._userManager = userManager;
    this._signInManager = signInManager;
    this._mapper = mapper;
}

Causes this error:

Unhandled exception. System.AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: TokenTracker.TokenTracker.Core.User.IAppUserManager Lifetime: Scoped ImplementationType: TokenTracker.Token
Tracker.Core.User.AppUserManager': Unable to resolve service for type 'Microsoft.AspNetCore.Identity.SignInManager`1[TokenTracker.TokenTracker.Core.User.ApplicationUser]' while attempting to activate 'TokenTracker.TokenTracker.Core.User.AppUserManager'.)
 ---> System.InvalidOperationException: Error while validating the service descriptor 'ServiceType: TokenTracker.TokenTracker.Core.User.IAppUserManager Lifetime: Scoped ImplementationType: TokenTracker.TokenTracker.Core.User.AppUserManager': Unable to resolve s
ervice for type 'Microsoft.AspNetCore.Identity.SignInManager`1[TokenTracker.TokenTracker.Core.User.ApplicationUser]' while attempting to activate 'TokenTracker.TokenTracker.Core.User.AppUserManager'.
 ---> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.SignInManager`1[TokenTracker.TokenTracker.Core.User.ApplicationUser]' while attempting to activate 'TokenTracker.TokenTracker.Core.User.AppUserManager'.
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, Type serviceType, Type implementationType, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(ServiceDescriptor serviceDescriptor, CallSiteChain callSiteChain)
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(ServiceDescriptor descriptor)
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.ValidateService(ServiceDescriptor descriptor)
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable`1 serviceDescriptors, IServiceProviderEngine engine, ServiceProviderOptions options)
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable`1 serviceDescriptors, IServiceProviderEngine engine, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory.CreateServiceProvider(IServiceCollection containerBuilder)
   at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter`1.CreateServiceProvider(Object containerBuilder)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at GetChain.Program.Main(String[] args) in C:\Users\icond\Documents\Coding\.NET Projects\GetChain\GetChain\Program.cs:line 7

I can however use version 2.1.1 with no issues.

Using scoped storage

I want to use multiple databases from a single app. This is resolved by using scopes instead of singletons for DI, but this library seems to use singletons. Is it possible to workaround that somehow?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.