简体   繁体   English

.NET Standard 2.0中的Microsoft.AspNet.Identity和Microsoft.AspNet.Identity.EntityFramework

[英]Microsoft.AspNet.Identity and Microsoft.AspNet.Identity.EntityFramework in .NET Standard 2.0

Background: The project we are wokring on consists of several solutions that share two libraries . 背景:我们正在启动的项目由共享两个库的几个解决方案组成。 Everything is written in .NET Framework 4.6.1 today. 如今,所有内容都是用.NET Framework 4.6.1编写的。 A goal for the project has been to adopt .NET Core for new projects and being able to run web applications in Docker . 该项目的目标是为新项目采用.NET Core ,并能够在Docker运行Web应用程序。

With the new release of .NET Standard 2.1 and the fact that .NET Framework 4.8 will remain on .NET Standard 2.0 rather than implement .NET Standard 2.1 it felt like the right time to start. 随着新版本的.NET Standard 2.1以及.NET Framework 4.8仍将保留在.NET Standard 2.0而不是实施.NET Standard 2.1事实,感觉像是开始的正确时机。 Immo Landwerth from Microsoft says this: Microsoft的Immo Landwerth表示:

But what is also true is that the rate of innovation in .NET Framework has to slow down in order to reduce breakage. 但是,事实也是如此,.NET Framework的创新速度必须放慢速度,以减少损坏。 In that sense, you should generally expect that most new features will only become available on .NET Core (and derived platforms, such as Xamarin, Mono, and Unity as they build from the same sources as .NET Core). 从这种意义上讲,您通常应该期望大多数新功能仅在.NET Core(以及从与.NET Core相同的来源构建的派生平台,例如Xamarin,Mono和Unity)上可用。

https://blogs.msdn.microsoft.com/dotnet/2018/11/05/announcing-net-standard-2-1/ https://blogs.msdn.microsoft.com/dotnet/2018/11/05/announcing-net-standard-2-1/

We would like to have access to new features in our new projects but do not want to convert every old project to .NET Core . 我们希望可以访问新项目中的新功能,但不想将每个旧项目都转换为.NET Core To keep compatibility between .NET Framework and .NET Core we decided to convert our shared libraries to .NET Standard 2.0 . 为了保持.NET Framework.NET Core之间的兼容性,我们决定将共享库转换为.NET Standard 2.0

https://docs.microsoft.com/en-us/dotnet/standard/net-standard https://docs.microsoft.com/zh-cn/dotnet/standard/net-standard

This worked really well apart from the following dependencies: 除了以下依赖性之外,此方法的确运行良好:

1. System.Net.Http.WebRequestHandler - Solved 1. System.Net.Http.WebRequestHandler-解决

Used for client certificates like this: 用于以下客户端证书:

WebRequestHandler requestHandler = new WebRequestHandler();

//Add certificate if setting exists
if (!string.IsNullOrEmpty(pushEvent?.CertificateThumbprint?.Thumbprint))
{
    var certificate = certificateService.GetClientCertificate(pushEvent?.CertificateThumbprint?.Thumbprint);
    if (certificate != null)
    {
        requestHandler.ClientCertificates.Add(certificate);
    }
}

var client = new HttpClient(requestHandler);

I found a NuGet for it but it seems malicious. 我为此找到了一个N​​uGet,但它似乎是恶意的。 The package links to Microsoft documentation as Project Site and has misspelled Microsoft as author, Microsfot. 该软件包以Project Site的形式链接到Microsoft文档,并误认为Microsoft是Microsfot的作者。 Reported it so Microsoft can have a look at it. 进行了报告,以便Microsoft可以进行查看。

https://www.nuget.org/packages/WebRequest.WebRequestHandler/ https://www.nuget.org/packages/WebRequest.WebRequestHandler/

However it seems we can change WebRequestHandler to HttpClientHandler to get it working out of the box. 但是,似乎我们可以将WebRequestHandler更改为HttpClientHandler以使其开箱即用。

2. System.Runtime.Remoting.Messaging -> CallContext.LogicalGetData - Solved 2. System.Runtime.Remoting.Messaging-> CallContext.LogicalGetData-已解决

Solved here: https://stackoverflow.com/a/53211839/3850405 在这里解决: https : //stackoverflow.com/a/53211839/3850405

3. Microsoft.AspNet.Identity.EntityFramework.IdentityUser 3. Microsoft.AspNet.Identity.EntityFramework.IdentityUser

We have a User Model that inherits from IdentityUser . 我们有一个继承自IdentityUser的用户模型。

public class AppUser : IdentityUser, ICurrentUser
{
    public bool LocalEnvironment { get; set; }

    public Guid? TokenId { get; set; }
}

4. Microsoft.AspNet.Identity.UserManager from assembly Microsoft.AspNet.Identity.Core 4.程序集Microsoft.AspNet.Identity.Core中的Microsoft.AspNet.Identity.UserManager

We keep our UserManager shared between the projects. 我们在项目之间共享UserManager Container is from SimpleInjector which is compatible with .NET Standard 2.0 . Container来自与.NET Standard 2.0兼容的SimpleInjector

public class AppUserManager : UserManager<AppUser>
{

    public AppUserManager(IUserStore<AppUser> store)
        : base(store)
    {

    }

    public static AppUserManager Create<AppContainer>() where AppContainer : Container, new()
    {
        var container = new AppContainer();
        var store = container.GetInstance<IUserStore<AppUser>>();

        var manager = new AppUserManager(store);

        manager.UserValidator = new UserValidator<AppUser>(manager)
        {
            AllowOnlyAlphanumericUserNames = false
        };


        return manager;
    }
}

If the EntityFramework NuGet is installed in the shared library the warning below is present. 如果在共享库中安装了EntityFramework NuGet ,则出现以下警告。 We can't risk that. 我们不能冒险。

Package 'EntityFramework 6.2.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. 使用“ .NETFramework,Version = v4.6.1”而不是项目目标框架“ .NETStandard,Version = v2.0”还原了软件包“ EntityFramework 6.2.0”。 This package may not be fully compatible with your project. 该软件包可能与您的项目不完全兼容。

I have read about why they put IdentityUser in the EF Library, IdentityUser is very EF specific. 我已经读到了为什么他们将IdentityUser放在EF库中, IdentityUser非常针对EF。 However it makes porting to .NET Standard 2.0. 但是,它可以移植到.NET Standard 2.0. harder. 更难。

Why is the IdentityUser class in the Microsoft.AspNet.Identity.EntityFramework namespace and not in the Core package? 为什么IdentityUser类在Microsoft.AspNet.Identity.EntityFramework命名空间中而不在Core包中?

I have also read that ASP.NET Core 2.0 have removed the base IdentityUser POCO (Plain Old CLR Object). 我还读过ASP.NET Core 2.0删除了基本的IdentityUser POCO(普通的旧CLR对象)。

Microsoft.AspNetCore.Identity and Microsoft.AspNetCore.Identity.EntityFrameworkCore only has dependencies to .NETStandard 2.0 and can be installed without a warning. Microsoft.AspNetCore.IdentityMicrosoft.AspNetCore.Identity.EntityFrameworkCore仅具有.NETStandard 2.0依赖关系,可以在不发出警告的情况下进行安装。 Do we need to upgrade Entity Framework and Identity on ASP.NET to Core or is there another way to get it working with .NET Standard ? 我们是否需要将ASP.NET上的Entity Framework和Identity升级到Core,还是有另一种方法使其与.NET Standard一起使用? Last step that we need to get it running. 我们需要运行它的最后一步。

https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/identity-2x?view=aspnetcore-2.1 https://docs.microsoft.com/zh-cn/aspnet/core/migration/1x-to-2x/identity-2x?view=aspnetcore-2.1

https://docs.microsoft.com/en-us/ef/efcore-and-ef6/side-by-side https://docs.microsoft.com/zh-CN/ef/efcore-and-ef6/side-by-side

Given that we only need EntityFramework 6.2.0 to work with both .NET Framework and .NET Core this will be solved in .NET Core 3 . 鉴于我们只需要EntityFramework 6.2.0即可与.NET Framework.NET Core这将在.NET Core 3解决。

.NET Core 3 is a major update which adds support for building Windows desktop applications using Windows Presentation Foundation (WPF), Windows Forms, and Entity Framework 6 (EF6). .NET Core 3是一个重大更新,它增加了对使用Windows Presentation Foundation(WPF),Windows Forms和Entity Framework 6(EF6)构建Windows桌面应用程序的支持。

https://blogs.msdn.microsoft.com/dotnet/2018/12/04/announcing-net-core-3-preview-1-and-open-sourcing-windows-desktop-frameworks/ https://blogs.msdn.microsoft.com/dotnet/2018/12/04/announcing-net-core-3-preview-1-and-open-sourcing-windows-desktop-frameworks/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 正确使用Microsoft.AspNet.Identity 2.0 - Correct use of Microsoft.AspNet.Identity 2.0 vsts构建在Microsoft.AspNet.Identity.EntityFramework上失败 - vsts build fails on Microsoft.AspNet.Identity.EntityFramework Microsoft.AspNet.Identity和Umbraco - Microsoft.AspNet.Identity and Umbraco 不使用Microsoft.AspNet.Identity.EntityFramework的自定义Asp.net MVC 5身份验证 - Custom Asp.net mvc 5 authentication without using Microsoft.AspNet.Identity.EntityFramework 在Microsoft.AspNet.Identity中使用UserManager和RoleManager; - Using UserManager and RoleManager in Microsoft.AspNet.Identity; 在MVC 5中使用Microsoft.AspNet.Identity进行搭建 - Scaffolding with Microsoft.AspNet.Identity in MVC 5 Microsoft.AspNet.Identity - 自定义POCO类 - Microsoft.AspNet.Identity - customize POCO class Nuget错误:“ EntityFramework 5.0.0”与“ Microsoft.AspNet.Identity.EntityFramework 1.0.0不兼容” - Nuget error: 'EntityFramework 5.0.0' is not compatible with 'Microsoft.AspNet.Identity.EntityFramework 1.0.0 为什么IdentityUser类在Microsoft.AspNet.Identity.EntityFramework命名空间中而不在Core包中? - Why is the IdentityUser class in the Microsoft.AspNet.Identity.EntityFramework namespace and not in the Core package? 使用继承的Context时如何消除Microsoft.AspNet.Identity.EntityFramework依赖关系? - How to eliminate the Microsoft.AspNet.Identity.EntityFramework dependency when using an inherited Context?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM