-
Notifications
You must be signed in to change notification settings - Fork 26
Concept ClockScope for using ScriptableObject #127
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?
Conversation
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.
Pull request overview
This PR refactors the clock system to use Unity's ScriptableObject pattern for configuration. It replaces the simple ClockModel with a more flexible ClockService that supports configurable time offsets, introducing a separation of concerns between service logic and configuration data.
- Renamed
IClockModeltoIClockServiceand replacedClockModelwithClockServicethat accepts configuration - Introduced
ClockConfigas a ScriptableObject withIClockConfiginterface for time offset configuration - Added
ClockScopeMonoBehaviour to bridge Unity's serialization system with the dependency injection framework
Reviewed changes
Copilot reviewed 15 out of 17 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| IClockService.cs | Renamed interface from IClockModel to IClockService |
| IClockConfig.cs | New interface defining configuration contract with TimeSpan Offset property |
| ClockService.cs | New service implementation that uses IClockConfig to apply time offset |
| ClockScope.cs | MonoBehaviour that exposes serialized ClockConfig to the DI system |
| ClockConfig.cs | ScriptableObject implementation of IClockConfig with serialized offset seconds |
| Composition.cs | Updated DI bindings to wire up IClockConfig and ClockService as singleton |
| Clock.cs | Updated to use IClockService instead of IClockModel |
| ClockModel.cs | Removed - replaced by ClockService |
| ClockConfig.asset | Unity asset file with default 360 second offset configuration |
| Resources.meta | Unity metadata for Resources folder |
| *.meta files | Unity metadata files for all new scripts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .Bind<IClockConfig>().To((ctx) => | ||
| { | ||
| ctx.Inject<ClockScope>(out var scope); | ||
| return scope.Config; | ||
| }) |
Copilot
AI
Dec 21, 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.
This binding creates a potential circular dependency. The IClockConfig binding injects ClockScope, but ClockScope.Start() calls Composition.Shared.BuildUp(this), which may attempt to resolve dependencies during injection. This could lead to runtime errors or infinite loops. Consider refactoring to avoid this circular dependency, such as making ClockScope register itself with the composition root instead of using injection here.
| ctx.Inject<ClockScope>(out var scope); | ||
| return scope.Config; | ||
| }) | ||
| .Bind().As(Singleton).To<ClockService>() |
Copilot
AI
Dec 21, 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.
The binding does not specify the interface type it's binding to. While this may work due to type inference, it's inconsistent with the explicit binding pattern used for IClockConfig on line 10. Consider using .Bind<IClockService>() for consistency and clarity.
| .Bind().As(Singleton).To<ClockService>() | |
| .Bind<IClockService>().As(Singleton).To<ClockService>() |
| { | ||
| [SerializeField] private ClockConfig _config; | ||
|
|
||
| public IClockConfig Config => _config; |
Copilot
AI
Dec 21, 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.
The _config field could be null if not assigned in the Unity Inspector. Consider adding a null check when accessing Config to prevent NullReferenceException, or validate that _config is not null in an Awake or Start method.
|
|
||
| void Start() | ||
| { | ||
| // Injects dependencies | ||
| Composition.Shared.BuildUp(this); | ||
| } |
Copilot
AI
Dec 21, 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.
The BuildUp call appears unnecessary as ClockScope doesn't have any properties marked with [Dependency] attribute. This call adds overhead without providing value. Consider removing it unless dependencies will be added in the future.
| void Start() | |
| { | |
| // Injects dependencies | |
| Composition.Shared.BuildUp(this); | |
| } |
|
|
||
| public ClockService(IClockConfig config) | ||
| { | ||
| _config = config; |
Copilot
AI
Dec 21, 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.
The config parameter and _config field should be validated for null to prevent NullReferenceException when accessing _config.Offset in the Now property. Consider adding a null check in the constructor or throwing an ArgumentNullException if config is null.
| _config = config; | |
| _config = config ?? throw new ArgumentNullException(nameof(config)); |
No description provided.