Integrate Spring.NET with Microsoft.Extensions.DependencyInjection
dotnet add package Spring.Extensions.DependencyInjection
integrate with Microsoft.Extensions.Hosting
var host = Host.CreateDefaultBuilder()
.UseServiceProviderFactory(new SpringServiceProviderFactory())
.ConfigureServices((context, services) =>
{
// ...
}).Build();
integrate with ASP.NET Core Minimal APIs
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseServiceProviderFactory(new SpringServiceProviderFactory());
building ServiceProviderFactory from exists ApplicationContext
using Microsoft.Extensions.DependencyInjection;
using Spring.Context.Support;
using Spring.Extensions.DependencyInjection;
// ...
var factory = new SpringServiceProviderFactory(options =>
{
var context = new CodeConfigApplicationContext();
context.ScanAllAssemblies();
context.Refresh();
options.Parent = context;
});
// or
//var factory = new SpringServiceProviderFactory(ContextRegistry.GetContext());
// or
//var factory = new SpringServiceProviderFactory(new XmlApplicationContext("objects.xml"));
// ...
building ApplicationContext from ServiceCollection
using Microsoft.Extensions.DependencyInjection;
using Spring.Context.Support;
using Spring.Extensions.DependencyInjection;
// ...
var factory = new SpringServiceProviderFactory();
var services = new ServiceCollection();
ConfigureServices(services);
var context = factory.CreateBuilder(services);
// ...
building ServiceProvider from Spring.NET ApplicationContext
using Microsoft.Extensions.DependencyInjection;
using Spring.Context.Support;
using Spring.Extensions.DependencyInjection;
// ...
var factory = new SpringServiceProviderFactory();
var services = new ServiceCollection();
ConfigureServices(services);
var context = factory.CreateBuilder(services);
var provider = factory.CreateServiceProvider(context);
// or directly building serviceProvider from exists ApplicationContext without integrate ServiceCollection
//var provider = factory.CreateServiceProvider(ContextRegistry.GetContext());
// ...
- the same service type in CodeConfigApplicationContext or XmlApplicationContext was preferred for SpringServiceProvider in SpringServiceScope