.NET Core is now Standard

You can now compile assemblies for .NET 6, .NET 8, and .NET 9. If you still want to support an old framework project, you can compile your assemblies for .NET Standard 2.0 -- if you don't want to continue using NDO 4.

The core of NDO 5 is not different from NDO 4, except for logging and dependency injection. However, NDO 4 will not see any further development.

You Need Two Packages

The NDO.dll package historically contained everything you needed to compile your assemblies. The assembly enhancer is now in a new package NDO.build, which you must include in your projects.

Symbol Packages

When we create the NDO packages, a special package file with the ending .snupkg is created. This contains the source code and symbols so you can debug in NDO without having to compile the source code. The snupgk files are published on nuget.org together with the nupkg files.

You need a Host

NDO now supports Microsoft's DependencyInjection. For this you need a host and you have to call AddNdo and BuildNdo in the initialization phase of the host. For a simple console application you can use the following base class:

internal class HostedProgram
{
protected IHost host;
public HostedProgram()
{
var builder = Host.CreateDefaultBuilder();
builder.ConfigureServices( services =>
{
services.AddLogging( b =>
{
b.ClearProviders();
b.AddConsole()
.AddFilter( "NDO", LogLevel.Debug );
} );
services.AddNdo( null, null );
} );
this.host = builder.Build();
this.host.Services.UseNdo();
}
}

You then have to work with instance methods in the derived class for the constructor to take effect.

Scoped DependencyInjection

When you instantiate the PersistenceManager with the default constructor, the ServiceProvider that existed when the system was initialized is used. In web applications, however, you want to use the request's ServiceProvider to receive "scoped" instances of your services. You receive the scoped ServiceProvider in a controller or in a Razor Page via DependencyInjection and can pass it to the PersistenceManager. This can then take the scope into account when creating objects.

public class MyController : ApiController
{
private readonly IServiceProvider serviceProvider;
public MyController (IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}
...
[HttpGet]
public IActionResult GetSomeData()
{
var pm = new PersistenceManager(this.serviceProvider);
var result = pm.Objects<SomeClass>().Where(c=>c.....).ResultTable();
// if SomeClass has a constructor parameter which is a scoped service,
// it will get the right parameter from the serviceProvider.
}
}