Closed benny-adiwijaya closed 2 years ago
Hi there, what is the problem you are having?
On Sun, Feb 27, 2022, 01:28 benny-adiwijaya @.***> wrote:
Hi, I have problem when try to save data to database using dependency injection & EF in the event, this is my code
// Events _driver.OnAfterUpload += async (sender, args) => { Console.WriteLine($"Uploaded to: {args.File.FullName}"); await _fileRepository.Create(new() { FullName = args.File.FullName }); };
So, is it possible to save data like this or there is another way?
— Reply to this email directly, view it on GitHub https://github.com/trannamtrung1st/elFinder.Net.Core/issues/23, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJU6TK7VGGCRR6EZRHQCLQLU5ELWVANCNFSM5PNMHDHQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you are subscribed to this thread.Message ID: @.***>
I got exception "Cannot access a disposed context instance. A common cause of this error is disposing a context instance that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.\nObject name: 'ApplicationDbContext'."
I think this is because the method return type is async void instead async Task
It is because the OnAfterload event is supposed to run synchronously. Making it async will result in the request completes then the context disposed before the event is called. I suggest not using async with EventHandler.
Closed due to inactivity. Please reopen this issue if the problem persists.
hi @benny-adiwijaya , you may want to take a look at #25.
Hi, I have problem when try to save data to database using dependency injection & EF in the event, this is my code
_driver.OnAfterUpload += async (sender, args) => { Console.WriteLine($"Uploaded to: {args.File.FullName}"); await _fileRepository.Create(new() { FullName = args.File.FullName }); };
So, is it possible to save data like this or there is another way?