Coder Social home page Coder Social logo

Comments (8)

alexandre-spieser avatar alexandre-spieser commented on June 11, 2024 3

yeah but it's not a 5 minute job 😄

from aspnetcore.identity.mongodbcore.

imclint21 avatar imclint21 commented on June 11, 2024 1

Oh I see, do you plan to migrate to net core 3?

from aspnetcore.identity.mongodbcore.

alexandre-spieser avatar alexandre-spieser commented on June 11, 2024

Hello,

The concept of DbContext does not exist with MongoDb, since the DbContext is EF/SQL specfic.
In the docs available here, you can created a MongoDbContext:
https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore/blob/master/README.md

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.

from aspnetcore.identity.mongodbcore.

imclint21 avatar imclint21 commented on June 11, 2024

Hi,

Thanks for your full answer, I already do that but when I build I have a missing DbContext error, it's the reason why I throw this issue!

Thank you

from aspnetcore.identity.mongodbcore.

alexandre-spieser avatar alexandre-spieser commented on June 11, 2024

Are you using Identity 2.0 ? This package does not support Identity 3.0.
Also, make sure that you do not have an EntityFramework packages doing Identity related work.
The stores used must only be the MongoDb ones, make sure you do not have any UserStore needing a DbContext.
You can look at the example of a Startup.cs here:
https://github.com/alexandre-spieser/AspNetCore.Identity.MongoDbCore/blob/master/sample/MongoIdentitySample.Mvc/Startup.cs

from aspnetcore.identity.mongodbcore.

imclint21 avatar imclint21 commented on June 11, 2024

I use net core 3 ^^

from aspnetcore.identity.mongodbcore.

alexandre-spieser avatar alexandre-spieser commented on June 11, 2024

yeah that might be the reason why it's not working, Identity 3.0 is almost a full rewrite, because they integrated the Identity Server package, the data access layer is totally different. This package does not support it yet.
Related to #20

from aspnetcore.identity.mongodbcore.

knight1219 avatar knight1219 commented on June 11, 2024

So interestingly, I've got it to compile and run using .net Core 3.1, but 26 tests seem to be failing (most seem to be related to the SecurityStamp). I'm not sure of the impact of those 26 tests failing but, its something.

from aspnetcore.identity.mongodbcore.

Related Issues (20)

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.