Enhancing Startup and DI #1445
Replies: 3 comments 2 replies
-
This sounds like a good idea, but there is currently no one working on such improvements. Probably because other things have more impact on the users. If you want something to happen, it is up to you to start a pull request and set things in motion. Stride is supported only by its community. |
Beta Was this translation helpful? Give feedback.
-
Microsoft's implementation is immutable, Stride's is mutable after construction. All the serviceRegistry.GetOrCreateService() would need to be removed, and replaced with clear three phase initialization: 1) Read configurations, 2) Initialize DI service descriptors, 3) Initialize Game, 4) Start Game. The methods and properties AddService(), RemoveService(), ServiceAdded and ServiceRemoved are not usable with System.IServiceProvider. On plus side, there would be actual injection into class, and support from larger maintainer. Best transition solution would be to add MS DI's along with Stride DI. Entity.Services would give deprecated warning. class Entity {
IServiceProvider ServiceProvider { get; }
[Deprecated("Use ServiceProvider")]
IServiceRegistry Services { get; }
} There could be a layered implementation for IServiceRegistry where services could be added. And when read from, it can source from fallback location (IServiceProvider). This is really easy to do. Most work would be with modifying the initialization structure of services and sample codes. |
Beta Was this translation helpful? Give feedback.
-
I have created a PR where I mostly copied how ASP Core does its startup, For anybody who's not familiar, the structure is this:
This is a breaking change, so it should be done in phases.
In the end we should check if we can just use the generic host which AmbulantRex mentioned in the beginning, |
Beta Was this translation helpful? Give feedback.
-
I noticed an ancient comment suggesting there were plans to use the Microsoft interfaces to structure dependency injection here:
stride/sources/core/Stride.Core/IServiceRegistry.cs
Lines 28 to 31 in f523477
On a tangential note, the generic host is something that could be leveraged to standardize application startup consistent with the .NET community. It offers some convenience for application lifetime management and configuration.
Beta Was this translation helpful? Give feedback.
All reactions