Cześć napisałem aplikację w winforms która posiada wartwę repozytorum oraz zaimplementowałem wzorzec UnitOfWork lecz gdy wykonuje jakieś zapytanie do bazy to mam bład:

'A second operation was started on this context before a previous operation completed. This is usually caused by different threads concurrently using the same instance of DbContext. For more information on how to avoid threading issues with DbContext, see https://go.microsoft.com/fwlink/?linkid=2097913.'

miałem kiedyś taki błąd w aplikacji webwoej leczy tutaj wystaczyło zmienić Lifetime na Transient:

services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(conntectionString), ServiceLifetime.Transient);

a jaki naprawić ten bład w aplikacji winforms ? Do wstrzykiwania zależności używam Ninject:

            Bind<ApplicationDbContext>().ToSelf();

            var assembly = Assembly.Load("DS.Repository");


            var registrations = from type in assembly.GetExportedTypes()
                                from service in type.GetInterfaces().Where(x => x.Name.EndsWith("Repository"))
                                select new { service, implementation = type };

            foreach (var reg in registrations)
            {
                Bind(reg.service).To(reg.implementation);
            }

            Bind(typeof(IUnitOfWork)).To(typeof(UnitOfWork));