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

Dependency Injection #84

Open
FejZa opened this issue Mar 21, 2024 · 2 comments
Open

Dependency Injection #84

FejZa opened this issue Mar 21, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@FejZa
Copy link
Contributor

FejZa commented Mar 21, 2024

Reality Collective - Service Framework Feature Request

Overview

Let's start talking about dependency injection and what it might look like for the service framework.
Ideally, I see this being implemented in 3 steps:

  1. Service injection for services
  2. Service injection for MonoBehaviours
  3. Service injection for plain C# classes

1. Service injection for services

In a fist step it would already be beneficial to support having the service manager inject dependencies into other services as requested. This would already save a lot of boilerplate code. Here is what I imagine that to look like

public override void Initialize(IInputService inputService, ILocomotionService locomotionService)
{
...
}

We use the Initialize() API to let developers specify any dependencies their service has and then have the service manager resolve those. We cannot use the service constructor for this, since that would introduce issues with dependencies not being registered with the service container yet. We should prefer method injection here so we can guarantee that all services are registered with the locator at the time of dependency injection.

@SimonDarksideJ
Copy link
Contributor

Service Injection is now complete as of #111

Module Injection is also needed.

@SimonDarksideJ
Copy link
Contributor

@FejZa can you describe patterns for 2 & 3, to give an indication as to their usage?

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

No branches or pull requests

2 participants