Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why IHost? #1

Closed
duongphuhiep opened this issue Aug 2, 2024 · 3 comments
Closed

Why IHost? #1

duongphuhiep opened this issue Aug 2, 2024 · 3 comments

Comments

@duongphuhiep
Copy link

duongphuhiep commented Aug 2, 2024

Hello, I'm not sure if I mis-understand something

The AppHost.Run() is not called anywhere. It was always Avalonia which manage the application lifecycle, not the IHost we created.

So what is the point of creating this IHost?

If it serves only for DI, then isn't it better to replace this IHost with a more appropriated interface IServiceProvider?

@parko65
Copy link
Owner

parko65 commented Aug 2, 2024

This is purely a trimmed down example taken from a WinUI3 app I have.

You are correct that if you want to just manage dependencies then go with the IServiceProvider approach. At the time this was posted there was hardly any documentation of what the best practice was to implement DI in an Avalonia app.

This implementation is commonly used in Desktop apps and follows best practices. Using the IHost enables me to easily read config files, run background services using IHostedService.

Just to appease I've added AppHost.Start() method.

@duongphuhiep
Copy link
Author

Thanks for the clarification, I discovered your repository while looking for a good Avalonia's DI guides.

The official documentation is not helpful at all: AvaloniaUI/avalonia-docs#525

@parko65
Copy link
Owner

parko65 commented Aug 2, 2024

Thanks for the clarification, I discovered your repository while looking for a good Avalonia's DI guides.

The official documentation is not helpful at all: AvaloniaUI/avalonia-docs#525

No, thank you for taking the time to investigate this repo and giving your thoughts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants