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

Increases usage of dependency injection #14

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

lewishazell
Copy link
Member

This is a first draft to demonstrate how we can use factories to inject services into objects which are created after startup.

The factories are created at startup, with necessary services injected, and pass these into the constructors of the objects they create.

In the factories submitted so far, I have injected the Log object to construct SocketListener/SocketConnector. The IRCd class no longer needs to know that these classes require a Log.

Unfortunately I couldn't inject the IRCd class into the factory because it would have been a circular dependency.

Any thoughts?

}

public SocketConnector CreateSocketConnector(IRCd ircd, ServerElement config) {
return new SocketConnector(log, ircd, config);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (and SocketListenerFactory) are only really just returning an object conditionless at the moment, I am guessing this is being done with a bigger picture in mind? I can see it nicely abstracts the Log creation but I don't really have the bigger picture in my head at the moment

@@ -43,7 +45,7 @@ public class SocketListener {
}
public virtual void Stop() {
if (_started) {
_ircd.Log.Debug($"Shutting down listener [IP: {Info.Host}, Port: {Info.Port}, TLS: {Info.IsTls}]");
log.Debug($"Shutting down listener [IP: {Info.Host}, Port: {Info.Port}, TLS: {Info.IsTls}]");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can already see that this is so much better than passing around everything inside IRCd

@lewishazell lewishazell changed the title Expand usage of dependency injection Increases usage of dependency injection Nov 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants