IObjectSpaceProviderFactory Interface
A service that provides access to Object Space Providers registered in your ASP.NET Core application.
Namespace: DevExpress.ExpressApp.Core
Assembly: DevExpress.ExpressApp.v24.1.dll
NuGet Package: DevExpress.ExpressApp
Declaration
Remarks
In ASP.NET Core Blazor and Web API applications created in v22.1+, IObjectSpaceFactory services use IObjectSpaceProviderFactory
to create the collection of IObjectSpaceProvider objects.
If you created your application in v21.2 or earlier, you need to use the Application Builder’s ObjectSpaceProviders property to register Object Space Providers instead of the XafApplication.CreateDefaultObjectSpaceProvider
method or XafApplication.CreateCustomObjectSpaceProvider
event. Refer to the following help topic for more information on how to do this: Integrate Application Builders into Existing Applications.
We strongly recommend this because the use of the XafApplication.CreateDefaultObjectSpaceProvider
method and XafApplication.CreateCustomObjectSpaceProvider
event conflicts with IObjectSpaceFactory
and IObjectSpaceProviderFactory
service usage.
The use of IObjectSpaceFactory instead of XafApplication
‘s members also improves the performance of your application because the application instance is not created in this case.
Note that applications without the Application Builder do not support the following services:
- IObjectSpaceFactory
- ISecurityProvider, UserManager, SignInManager, and
IStandardAuthenticationService
- Backend Web API Service
Add a Custom Object Space Provider to an ASP.NET Core Blazor Application
The Application Builder builds an IObjectSpaceProviderFactory
, so you do not need to implement it in your code. You can add a new IObjectSpaceProvider
to the builder:
File: MySolution.Blazor.Server\Startup.cs.
public class Startup {
// ...
public void ConfigureServices(IServiceCollection services) {
// ...
services.AddScoped<CustomObjectSpaceProvider>();
services.AddXaf(Configuration, builder => {
// ...
builder.ObjectSpaceProviders
.AddSecuredXPO(() => {
//...
})
.AddNonPersistent()
.Add((IServiceProvider services) =>
services.GetRequiredService<CustomObjectSpaceProvider>());
// ...
});
// ...
}
}
Implement a Custom IObjectSpaceProviderFactory Service
If you need to use this service but you cannot integrate the Application Builder into your application, you can register a custom IObjectSpaceProviderFactory
service.
Implement the
IObjectSpaceProviderFactory
in your class. You can use the following examples as is or as a base for your custom implementation.Application Builder analogs:
XPO - AddSecuredXpo + AddNonPersistent EF Core - AddSecuredEFCore + AddNonPersistentFile: MySolution.Module\CustomObjectSpaceProviderFactory.cs.
using System.Collections.Generic; using DevExpress.ExpressApp; using DevExpress.ExpressApp.Core; using DevExpress.ExpressApp.DC; using DevExpress.ExpressApp.Security; using DevExpress.ExpressApp.Security.ClientServer; using DevExpress.ExpressApp.Xpo; public sealed class CustomObjectSpaceProviderFactory : IObjectSpaceProviderFactory { readonly ISecurityStrategyBase security; readonly ITypesInfo typesInfo; readonly IXpoDataStoreProvider dataStoreProvider; public CustomObjectSpaceProviderFactory(ISecurityStrategyBase security, ITypesInfo typesInfo, IXpoDataStoreProvider dataStoreProvider) { this.security = security; this.typesInfo = typesInfo; this.dataStoreProvider = dataStoreProvider; } public IEnumerable<IObjectSpaceProvider> CreateObjectSpaceProviders() { yield return new SecuredObjectSpaceProvider((ISelectDataSecurityProvider)security, dataStoreProvider, true); yield return new NonPersistentObjectSpaceProvider(typesInfo, null); } }
Register your implementation as a service before the
AddXaf
extension methods:services.AddSingleton<IObjectSpaceProviderFactory, CustomObjectSpaceProviderFactory>();