expressappframework-404391-data-security-and-safety-security-system-security-tiers-middle-tier-security-ef-core-add-middle-tier-to-existing-app.md
This topic contains step-by-step instructions on how to add a Middle Tier Security project with an Entity Framework Core DbContext to a XAF Windows Forms application with EF Core and Security.
A Middle Tier security project cannot be added separately. You need to create a new solution with Middle Tier security enabled, then copy and add the security project to your solution, and configure the application.
If the name of the EF Core DbContext class in the generated Middle Tier Security project differs from the DbContext name in the the main module project (MySolution.Module), change the DbContext class name in the following files:
Add the following NuGet package to the MySolution.Win project: DevExpress.ExpressApp.Security.EFCore.Extensions.Win.
Because the Middle Tier Security uses the XAF Security System, it requires that the ApplicationUser and ApplicationUserLoginInfo persistent classes are defined within your application to store user account data. If the MySolution.Module project does not contain these classes, add them manually as described in the following topic: Use the Security System.
If the MySolution.Win\Program.cs contains the following autogenerated code lines, delete them:
If the WinForms application’s Startup.cs file contains the following code used to update the database, remove the code.
If the application’s Startup.cs file contains code that adds EF Core ObjectSpace providers, delete the line that configures the database provider’s connection string and replace it with code that configures the connection to the Middle Tier Security server. Additionally, replace the code that registers the secured object space with the version without security:
If the application’s Startup.cs file contains code that adds Integrated Security or Windows Security, remove this code.
In the same file, add code that initializes Middle Tier Security.
If the WinForms application uses the Audit Trail module, remove the code that registers it from the WinForms application.
Right-click the Solution node in the Solution Explorer and choose Properties. In the Solution Property Pages dialog, expand the Common Properties node and select Startup Project. Choose the Multiple Startup Projects option and select the Start action for the Web API and MySolution.Win projects.
Click the Run button to run the application.
See Also
Add EF Core Middle Tier Security to an Existing WinForms Application
Connect a Non-XAF Application to a Middle Tier Security Server (EF Core)