Hi,
I have been trying to find information or documentation for upgrading a SharpArch solution from .net Framework to .net Core.
This also involves upgrading from SharpArch v4 to v 5 or v6.
I have a working .net Core version with SharpArch v5, but seem to be having problems with transaction or session management, using this code:
public IServiceCollection AddNHibernateWithSingleDatabase(
IServiceCollection services,
Func<IServiceProvider, NHibernateSessionFactoryBuilder> configureSessionFactory,
Func<ISessionBuilder, IServiceProvider, ISession> sessionConfigurator = null,
Func<IStatelessSessionBuilder, IServiceProvider, IStatelessSession> statelessSessionConfigurator = null
)
{
if (services == null) throw new ArgumentNullException(nameof(services));
if (configureSessionFactory == null) throw new ArgumentNullException(nameof(configureSessionFactory));
services.AddSingleton(sp =>
{
var sfBuilder = configureSessionFactory(sp);
var sessionFactory = sfBuilder.BuildSessionFactory();
return sessionFactory;
});
services.AddScoped(sp =>
{
var sessionFactory = sp.GetRequiredService<ISessionFactory>();
var session = sessionConfigurator == null ? sessionFactory.OpenSession() : sessionConfigurator(sessionFactory.WithOptions(), sp);
return session;
});
services.AddScoped(sp =>
{
var sessionFactory = sp.GetRequiredService<ISessionFactory>();
var session = statelessSessionConfigurator == null
? sessionFactory.OpenStatelessSession()
: statelessSessionConfigurator(sessionFactory.WithStatelessOptions(), sp);
return session;
});
services.AddScoped<TransactionManager>();
services.AddTransient<INHibernateTransactionManager>(sp => sp.GetRequiredService<TransactionManager>());
services.AddTransient<ITransactionManager>(sp => sp.GetRequiredService<TransactionManager>());
return services;
}
I then tried to upgrade to v6. I went for v5 initially as my repository implementations are not async.
With v6, the .net Core DI is telling me my Repository implementation cannot be converted to the service interface:
Implementation type 'SharpArch.NHibernate.NHibernateRepository`1[xxx]' can't be converted to service type 'SharpArch.Domain.PersistenceSupport.IAsyncRepository`1[xxx]
My guess is that I haven't reimplemented the Repositories correctly, but I am not sure what I'm doing wrong (I am new to async coding)
Any insights or links greatly appreciated!
Henry