[go: up one dir, main page]

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

Replace primitive injection with IConfiguration #887

Merged

Conversation

wtaylor
Copy link
Contributor
@wtaylor wtaylor commented Feb 13, 2019

Description
Currently, we create all instances of our registered services manually in ApplicationHost. This is very much an anti pattern for Dependency Injection. The correct way is to create the dependency injection container and register services against it with the specified creation policy (singleton, per instance, per scope etc.). This allows the container to manage the lifetime of the objects that it creates and automatically calls Dispose on services that implement IDisposable.

This commit is just a start to removing the primitives from services that are manually created and registered. We need to do this to eventually get to a point where the container can be responsible for the creation of these services.

I'm following the guidance from the dot net core developer reference -> https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.1

Copy link
Contributor
@JustAMan JustAMan left a comment

Choose a reason for hiding this comment

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

CI is failing, please fix the build :)

_environmentInfo = environmentInfo;
_defaultDirectory = defaultDirectory;
_defaultDirectory = configuration["ManagedFileSystem:DefaultDirectory"];

// On Linux with mono, this needs to be true or symbolic links are ignored
Copy link
Contributor

Choose a reason for hiding this comment

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

thinking out loud, not necessary to implement in this PR:
if this is for mono only, maybe we should drop that?..

Copy link
Contributor
@JustAMan JustAMan left a comment

Choose a reason for hiding this comment

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

Code changes are fine now.

I would like to see the reasoning for extracting them to a separate class, though, without understanding the reasons I cannot approve.

public static readonly Dictionary<string, string> Configuration = new Dictionary<string, string>
{
{"ManagedFileSystem:DefaultDirectory", null},
{"ManagedFileSystem:EnableSeparateFileAndDirectoryQueries", "True"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this option at all? Some old comments said it had to be tweaked for Mono on Linux, but we had it hardcoded to true since we are on .net core. I suggest removing this option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both these options are unnecessary actually. Removed them both.

Program.cs and ApplicationHost are both getting really large, the extra class let's us configure options for ServerImplementations services that only devs can toggle and not users while still providing a centralised place for them. With this implementation, if we want to let the user configure a specific option, it's as simple as removing it from the ConfigurationOptions dictionary and adding it to an external configurations file that also get''s added to the IConfiguration.

This will make it easier to move dependency registration
to a system without having to new up all the services first.
Moved the primitives to an IConfiguration which is much easier to inject.
@wtaylor wtaylor force-pushed the replace-primitives-with-iconfiguration branch from 5a77f15 to 18ae107 Compare February 17, 2019 14:10
Copy link
Contributor
@JustAMan JustAMan left a comment

Choose a reason for hiding this comment

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

Now changes make more sense to me.
One question pending though, would like a clarification from you and a look-through from either @cvium or @Bond-009

Jellyfin.Server/Program.cs Show resolved Hide resolved
.Build();
return new ConfigurationBuilder()
.SetBasePath(appPaths.ConfigurationDirectoryPath)
.AddJsonFile("logging.json")
Copy link
Member

Choose a reason for hiding this comment

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

The config is still called logging.json, you can either create a separate config file for the other settings or rename this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have any other user configurable IConfiguration sources at the moment so keeping it as logging.json still makes sense. We can also add multiple JsonFiles so we can extend that builder when we have another config file to add

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, you're using the InMemoryCollection 👍

@JustAMan JustAMan merged commit 13f2783 into jellyfin:master Feb 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants