Caliburn-Micro / Caliburn.Micro

A small, yet powerful framework, designed for building applications across all XAML platforms. Its strong support for MV* patterns will enable you to build your solution quickly, without the need to sacrifice code quality or testability.
http://caliburnmicro.com/
MIT License
2.8k stars 778 forks source link

ApplicationDbContext and container (composition root) #793

Closed yooplait closed 2 years ago

yooplait commented 2 years ago

Hi,

I'm asking myself if it's possible to simulate de DbContext like i do inside API :

services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("XXX")))

I can do this inside Configure but it's not disposed automatically :

this.container.PerRequest();

Is it possible to simulate this ?

Thank you !

vb2ae commented 2 years ago

What version of Caliburn.Micro are you using? What type of app are you working on? (WPF, Xamarin.Forms, UWP) What version of .net are you using? (.net framework, .net core, .net 5 or 6)

How do you know the DbContext is not disposing?

yooplait commented 2 years ago

Hi thank you for your answer.

I'm using WPF with Caliburn Micro 4.0.173 (UI), BU and DAL (EF).

I can do this to inject but it's never disposed like microsoft :

this.container.PerRequest()

Of course i can call Dispose() method by myself but it's not automatically.

Thank you !

vb2ae commented 2 years ago

I created a sample that allows you Microsoft extension dependency inject as your old container

https://github.com/vb2ae/CaliburnMicroMicosoftDI/

yooplait commented 2 years ago

Wow, thank you so much for your help! 👌