Removal of OpenIddict.Models in OpenIddict RC3
See original GitHub issueStarting with RC3, OpenIddict will no longer come with a default set of entities and stores base classes.
Why?
In the previous iterations of OpenIddict, an important effort was made to create a shared set of entities (contained in the OpenIddict.Models
package) that could be used not only by the official Entity Framework 6.x and Entity Framework Core stores, but also by third-party/custom stores.
This pattern had many pros - like avoiding code duplication or having base classes that simplify the development of custom stores (which is why it was also eventually adopted by the ASP.NET team for ASP.NET Core Identity in 2.0).
Unfortunately, this approach had also a major issue: we had to design the default entities as “lowest common denominators”, so that they could be used by all/most ORMs or document databases. In practice, this meant that things like OpenIddictApplication.RedirectUris
or OpenIddictApplication.PostLogoutRedirectUris
had to be represented as JSON-serialized strings
for SQL-oriented ORMs like EF 6.x and EF Core to work natively.
In the document databases world, entities are generally schema-less, which offers a greater flexibility. A NoSQL database like MongoDB can easily store and efficiently index JSON arrays, which means OpenIddictApplication.RedirectUris/PostLogoutRedirectUris
are best represented as arrays of strings (string[]
).
The conclusion was clear: we couldn’t have the best performance by using non-optimized entities.
What will change?
In RC3, each stores package will come with its own models you’ll be able to use exactly like in the previous iterations.
How do I update my code?
First, make sure you don’t reference the obsolete OpenIddict.Models
or OpenIddict.Stores
packages. The new models are automatically referenced by the stores packages they belong to and you don’t need to add any reference to use them.
Then, update your Startup.ConfigureServices()
method to use the new helpers. For instance:
services.AddOpenIddict()
// Register the OpenIddict core services.
.AddCore(options =>
{
options.UseEntityFrameworkCore()
.UseDbContext<ApplicationDbContext>();
});
If you prefer using long
as the key type (with the default entities), use ReplaceDefaultEntities
:
services.AddOpenIddict()
// Register the OpenIddict core services.
.AddCore(options =>
{
options.UseEntityFrameworkCore()
.UseDbContext<ApplicationDbContext>()
.ReplaceDefaultEntities<long>();
})
If you want to use your own entities instead of the default EF Core ones:
services.AddOpenIddict()
// Register the OpenIddict core services.
.AddCore(options =>
{
options.UseEntityFrameworkCore()
.UseDbContext<ApplicationDbContext>()
.ReplaceDefaultEntities<MyApp, MyAuth, MyScope, MyToken, long>();
})
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (5 by maintainers)
Top GitHub Comments
Are you migrating from an old OpenIddict version (e.g RC1?). If so, you’ll have to update your DB schema. Read https://openiddict.github.io/openiddict-documentation/guide/migration.html for more information.
Just wondering when will the samples be updated to reflect this change?
I am having some trouble migration from rc2 - when calling services.AddOpenIddict, where do I put the additional calls to methods such as AddMvcBinders, RegisterScopes, SetAccessTokenLifetime etc.?
These methods are not available on the options object inside the the AddOpenIddict method or the AddCore method.
For example, inside of AddOpenIddict it used to look like this: