Version Upgrade and .net Core migration information

48 views
Skip to first unread message

he...@failbettergames.com

unread,
Mar 30, 2021, 11:01:42 AM3/30/21
to S#arp Architecture
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 

vkr2...@gmail.com

unread,
Mar 31, 2021, 11:24:18 AM3/31/21
to S#arp Architecture
Hello Henry,
How do you register your repositories?

Henry Senior

unread,
Mar 31, 2021, 11:39:47 AM3/31/21
to sharp-arc...@googlegroups.com
Hi, thanks for getting back to me!

I register them like this in SharpArch v 5
services.AddScoped(typeof(IRepository<>), typeof(NHibernateRepository<>));

When I moved to v6 and async repositories I changed to 
services.AddScoped(typeof(IAsyncRepository<>), typeof(NHibernateRepository<>));

and got the following error:

Implementation type 'SharpArch.NHibernate.NHibernateRepository`1[xxx]' can't be converted to service type 'SharpArch.Domain.PersistenceSupport.IAsyncRepository`1[xxx]

The solution builds ok. I did some runtime reflection checks to ensure that instances of the repos did indeed implement the interface.
I am a bit lost!

If you know of any information regarding how to register sessions, sessionFactories, transactionManagers in SharpArch 5, and also what has become of UnitOfWork in SharpArch v 6, I would be very grateful!  

Henry

--
You received this message because you are subscribed to a topic in the Google Groups "S#arp Architecture" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sharp-architecture/NU5pYioXXgk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sharp-architect...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sharp-architecture/c94a3758-f31a-4224-9997-0d648118c860n%40googlegroups.com.

vkr2...@gmail.com

unread,
Apr 18, 2021, 4:01:02 PM4/18/21
to S#arp Architecture
Sorry for long delay, 

Try to use `IAsyncRepositoryWithTypedId` instead if IAsyncRespository.

I prefer would recommend to use Autofac instead of MS DI.

I'll try to add MS DI example later
Reply all
Reply to author
Forward
0 new messages