XPO - .NET Core Enhancements (v18.1)

Extended database support
With our upcoming release (v18.1), XPO for .NET Core / .NET Standard 2.0 will support the Oracle Data Provider 12.2 for .NET Core in addition to SQL Server, MySql, PostgreSQL, FireBird and SQLite. As we noted in our introductory post, the lack of support for other providers is not a limitation of XPO - only a function of support from RDBMS vendors. Once these RDBMS vendors support .NET Standard 2.0, we will test XPO against these backend providers and will add them to our supported list once our internal qualification requirements have been met. See Also: How to implement a custom XPO connection provider for AdoNetCore.AseClient.

XPO Profiler supports ASP.NET Core projects
As some of you already know, XPO Profiler is a tool designed to discover performance bottlenecks and code issues. Profiling logs include SQL queries, session method calls, query duration, passed parameters, and callstacks. To enable performance profiling in your ASP.NET Core projects, you'll need to add a special API Controller:

using Microsoft.AspNetCore.Mvc;
using DevExpress.Xpo.Logger;

namespace DevExpress.Xpo.AspNetCoreMvcDemo.Controllers {
    public class XpoLoggerController : Controller {
        readonly static LoggerBase logger = new LoggerBase(50000);
        static XpoLoggerController() {
            LogManager.SetTransport(logger);
        }
        [HttpGet]
        public LogMessage[] GetCompleteLog() {
            return logger.GetCompleteLog();
        }
        [HttpGet]
        public LogMessage GetMessage() {
            return logger.GetMessage();
        }
        [HttpGet]
        public LogMessage[] GetMessages(int messagesAmount) {
            return logger.GetMessages(messagesAmount);
        }
    }
}
Complete documentation will ship with our official v18.1 release:  Connect the XPO Profiler to an ASP.NET Core Application. In the meantime, you can use our GitHub demo with the current beta.

Dependency Injection for ASP.NET Core projects
We've implemented new extension methods for the standard IServiceCollection interface to register useful XPO services for the ASP.NET Core pipeline. This follows best practices for the platform and allows you to automatically manage XPO’s data layer and session life cycle as needed.

To call these extensions, the Microsoft.Extensions.DependencyInjection namespace must be imported. Here is an example of the modified ConfigureServices method in the Startup class inside an ASP.NET Core project:

        public void ConfigureServices(IServiceCollection services) {
            services.AddXpoDefaultUnitOfWork(true, options =>
options.UseConnectionString(Configuration.GetConnectionString("SQLite"))
                    .UseConnectionPool(false)
                    .UseThreadSafeDataLayerSchemaInitialization(true)
.UseAutoCreationOption(DB.AutoCreateOption.DatabaseAndSchema)
                    .UseEntityTypes(new Type[] { typeof(User) })
            );
            services.AddMvc();
        }

You can access  or resolve the UnitOfWork service in your Controllers (example), Views markup or Startup (example) class using standard ASP.NET Core techniques. For more information, refer to the Dependency injection in ASP.NET CoreDependency injection into controllers in ASP.NET Core and Dependency injection into views in ASP.NET Core articles in Microsoft documentation.  Additional XPO examples will be available with the official release at ASP.NET Core Dependency Injection in XPO.

BONUS: I also have an XPO .NET Core version up and running with the Mono runtime on WebAssembly in a Blazor app for both standalone and ASP.NET Core hosted deployment. The example below was used for the in-memory data store within a web browser:

            var serviceProvider = new BrowserServiceProvider(services => {
                services.AddXpoDefaultUnitOfWork(true, options =>
                    options.UseInMemoryDataStore(true)
                    .UseAutoCreationOption(AutoCreateOption.DatabaseAndSchema)
                    .UseThreadSafeDataLayerSchemaInitialization(true)
                    .UseConnectionPool(false)
                    .UseEntityTypes(new Type[] { typeof(WeatherForecast) })
                );
            });

NOTE: we do not officially support WebAssembly-based .NET runtimes at this stage (and of course, Blazor is currently an experimental project). I did this test just for fun and research purposes.  Are you also interested in testing XPO with Blazor? Leave a comment to this post and I will email you my working XPO sample.


Love XPO and want to help us promote it? Add the package through Nuget.org instead of DevExpress Nuget!

Hi Dennis,

thanks for the news! Awaiting the official release of 18.1!

I like the idea of your Blazor-POC. Can you send me your working example?  You should find my email-address in your customer-data...

I tested Oracle with XPO and 18.1 beta - works like a charme!

16 May, 2018

Thanks for your feedback, Dietmar!

Sure, here we go: community.devexpress.com/.../Blazor0.3_XPO181.zip

16 May, 2018

Hi Dennis,

now that 18.1.3 is released, I try to find more information about the DI-extension-methods (like AddXpoDefaultUnitOfWork) you provide. I cannot find any documentation (neither off- nor online). Do I miss something?

I also tried to find it in the sources (Universal subscription) but the only match I receive in a full-text search over the compelte directory is in the DevExpress.Xpo.v18.1.dll, but not in sources...

Do I miss something?

18 May, 2018

Hello Dietmar,

The documentation for DI extension methods is not ready yet. We plan to publish it next week (you will receive a notification). We apologize for this inconvenience. Currently, you can find examples of using some of these methods in the Dennis' comment above.

18 May, 2018

Dietmar, please refer to the ASP.NET Core Dependency Injection in XPO article (https://www.devexpress.com/kb=T637597).

21 May, 2018

Can't wait to have blaser released and even better devexpress support for it and webassembly

26 May, 2018

Thanks for your interest, Hedi!

27 May, 2018

Please login or register to post comments.