Connect a Non-XAF Application to a Middle Tier Security Server (EF Core)
- 2 minutes to read
The following steps outline how to connect a non-XAF .NET application to a database through the EF Core-based Middle Tier Security application.
Note
The technique described in this topic was not tested with .NET MAUI and Blazor WebAssembly clients. With these platforms, we recommend that you use our Web API Service on the backend as demonstrated in the following examples on GitHub:
Install the following NuGet package: DevExpress.ExpressApp.EFCore.
Create a Middle Tier client:
// The following code sample sets the Middle Tier server URL to the default value for debug mode // This setting may be different in your application // You can check this setting in the following Middle Tier project's file: Properties/launchSettings.json var middleTierClient = new MiddleTierClientBuilder<MainDemoDbContext>() .UseServer(" https://localhost:44319/ ") .UsePasswordAuthentication("John", "") .Build();
After the client successfully connects to the Middle Tier server and passes authentication, you can access security permissions for the current user.
var objectSpace = middleTierClient.CreateObjectSpace(); bool isReadGranted = middleTierClient.Security.CanRead<Employee>(objectSpace); bool isWriteGranted = middleTierClient.Security.CanWrite<Employee>(objectSpace, nameof(Employee.Address1));
You can use the Middle Tier Security as a database provider to access data through an EF Core
DbContext
or Object Space:// Use DbContext to access data: var dbContext = middleTierClient.CreateDbContext(); var users = dbContext.Employees.ToList(); // Use Object Space to access data: var objectSpace = middleTierClient.CreateObjectSpace(); var users = objectSpace.GetObjectsQuery<Employee>().ToList();
You need to dispose the Middle Tier client when it is no longer needed:
middleTierClient.Dispose();
Tip
You can use DevExpress Template Kit for Visual Studio to create WinForms and WPF applications that implement the described approach.