Skip to main content
All docs
V23.2
.NET 6.0+
  • The page you are viewing does not exist in the .NET Framework 4.5.2+ platform documentation. This link will take you to the parent topic of the current section.

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.v23.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

public interface IObjectSpaceProviderFactory

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:

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.

  1. 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 + AddNonPersistent

    File: 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);
        }
    }
    
  2. Register your implementation as a service before the AddXaf extension methods:

    services.AddSingleton<IObjectSpaceProviderFactory, CustomObjectSpaceProviderFactory>();
    
See Also