Quantcast
Viewing all articles
Browse latest Browse all 2399

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.

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. 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.

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.

Image may be NSFW.
Clik here to view.

Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 2399

Trending Articles