-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Stride Gamebuilder as an alternative for .NET IOC startup #2806
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
base: master
Are you sure you want to change the base?
Changes from all commits
75f1515
2372862
2f7f213
5e82aa1
7136214
aa3c9fe
257c458
e83810a
18397c5
2588b5f
f1f7b49
938a50c
c2de7f4
3b26a45
384dd48
ceaec04
8723abe
7590a43
6f02a8b
9f7bd52
848bd10
731610d
8c7eaea
415cd6f
08dc3ce
a51d8cf
1bcc2e5
c5d1c3d
1f8eba6
a315d2b
0ed0012
4718339
5d34b28
c252f6e
850659d
1432594
4e241b3
bdc76e1
0742e53
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,151 @@ | ||||||||||||||||||||||||||||
| using System; | ||||||||||||||||||||||||||||
| using System.Collections.Generic; | ||||||||||||||||||||||||||||
| using Microsoft.Extensions.DependencyInjection; | ||||||||||||||||||||||||||||
| using Stride.Core; | ||||||||||||||||||||||||||||
| using Stride.Core.Diagnostics; | ||||||||||||||||||||||||||||
| using Stride.Games; | ||||||||||||||||||||||||||||
| using Stride.Input; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| namespace Stride.Engine.Builder; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||
| /// Helps build the game and preps it to be able to run after <see cref="Build"/>. | ||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||
| public class GameBuilder : IGameBuilder | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||
| /// This is used to allow the same instance to be registered multiple times as different interfaces or types. This was done due to how <see cref="IServiceRegistry"/> works."/> | ||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||
| public Dictionary<Type, object> InternalServices { get; internal set; } = []; | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||
| /// This allows for Service to be registered through DI. | ||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||
| public IServiceCollection Services { get; internal set; } = new ServiceCollection(); | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||
| /// This is a direct reference to the game systems collection of the <see cref="GameBase"/>. | ||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||
| public GameSystemCollection GameSystems { get; internal set; } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||
| /// Adds log listeners to the game on <see cref="Build"/>. This is registered first so it will log build errors if they occur."/> | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| /// Adds log listeners to the game on <see cref="Build"/>. This is registered first so it will log build errors if they occur."/> | |
| /// Adds log listeners to the game on <see cref="Build"/>. This is registered first so it will log build errors if they occur. |
Copilot
AI
Nov 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential null reference exception. When instance is null after both checks (lines 82-96), calling Game.Services.AddService(instance, service.Key) on line 99 will pass a null value which may cause issues. Consider logging a warning or skipping the service registration when the instance cannot be resolved.
| _log.Info($"Registering service {service.Key.Name}."); | |
| Game.Services.AddService(instance, service.Key); | |
| InternalServices[service.Key] = instance; | |
| if (instance != null) | |
| { | |
| _log.Info($"Registering service {service.Key.Name}."); | |
| Game.Services.AddService(instance, service.Key); | |
| InternalServices[service.Key] = instance; | |
| } | |
| else | |
| { | |
| _log.Warning($"Could not resolve service {service.Key.Name}. Skipping registration."); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using Microsoft.Extensions.Hosting version 9.0.5. While this is the latest version, please verify this version is compatible with all target frameworks and platforms that Stride supports (including mobile platforms like Android and iOS). Note that version 9.x may have different requirements than earlier versions.