vlingo-net / xoom-net-actors

Type safe Actor Model toolkit for reactive concurrency and resiliency using C# and other .NET languages.
Mozilla Public License 2.0
39 stars 18 forks source link

Load properties from App.config (or something similar) #23

Closed zpbappi closed 5 years ago

zpbappi commented 5 years ago

Currently the Vlingo.Actors/Properties class loads properties/settings from a vlingo-actors.properties file. It needs to be modified to read from any standard configuration provider (such as App.config or Web.config). Please discuss your idea here before starting any implementation.

ChicagoDave commented 5 years ago

There really shouldn't be any configuration in the library. Any data required by the library should be injected when instantiated.

VaughnVernon commented 5 years ago

@ChicagoDave We have a plugin architecture which means you can extend the actor runtime. You can see an example on the Java side. This is what @zpbappi ported intact and why we need the .NET idiomatic implementation.

https://github.com/vlingo/vlingo-actors/blob/master/src/test/resources/vlingo-actors.properties

These configurations can be managed in code, but some prefer file-based configurations, especially for heterogeneous environments.

ChicagoDave commented 5 years ago

So looking into this it seems Microsoft has finally fixed a long-standing broken paradigm where you could only use standard configurations from the App or Web context. There's a new .NET Standard/Core implementation under Microsoft.Extensions.Configuration that allows you to implement a variety of configurations. (https://docs.microsoft.com/en-us/dotnet/api/microsoft.extensions.configuration?view=aspnetcore-2.2)

VaughnVernon commented 5 years ago

Great! I think @zpbappi settled on Core2, not sure about the minor version (2.1?). I'd like feedback from him and @tjaskula but seems like what we want.

ChicagoDave commented 5 years ago

I'm sure that API is in 2.0 going forward. The vlingo library is in .NET Standard and the unit tests are in .NET Core. .NET Standard is the sharable foundation between all .NET implementations and .NET Core is always directly aligned with it. .NET Core has the command line implementation. (@zpbappi chose well)

zpbappi commented 5 years ago

@ChicagoDave the configuration is not in the library, it is in the test project. I just don't like the fact that we are loading from a fixed file named and formatted in a specific way. I would rather have the freedom to have the configuration in whatever format is more appropriate for the consumer project (web.config, app.config, config.json, fluent config using code, etc). We have to ensure that Vlingo .NET can be used in different environments, regardless of the dotnet runtime they have. This is the main reason for selecting NETStandard. Currently, I am restricting all the libraries to target netstandard2.0. I would, however, like to target lower versions of NETStandard. To do that, I will have to stop using System.Threading.Thread (and, few other classes). I believe we can get there. @tjaskula is tackling the Thread classes. For tests, they are running in NETCore2.0. They can be made .NET Framework, or Mono as well. In theory, it does not matter what the the runtime is, as long as it implements the library's NETStandard version or higher. I have a plan to configure multi-runtime build/test later in our CI. But, it's just not the most important thing right now.

Okay, having stated the whole background and drive, I think I was able to convey that we need a solution that can work with NETStandard2.0 or earlier (better). I would really like to avoid conditional targetting for each different runtime, which can happen if we use something that is not in NETStandard yet.

VaughnVernon commented 5 years ago

@zpbappi Regarding,

I just don't like the fact that we are loading from a fixed file named and formatted in a specific way.

I thought we are discussing the port of vlingo-actors.properties from the Java side. What is your thought about not retaining a similar filename? Are you thinking that .NET would be happy to put vlingo-specific configurations into their own application/service config file(s)? No criticism, only looking for clarification.

tjaskula commented 5 years ago

Just for information, Akka.NET keeps still the same java-ich configuration for reference. Even if we adapt it to .NET we should keep the same keys and hierachies

zpbappi commented 5 years ago

@VaughnVernon I don't have any issue with the file name. And, the current code can actually load and parse settings from the vlingo-actors.properties file. It also supports fluent configuration for plugins. That functionality is there and it should always be there. What it does not support is loading the configuration from an already existing standard configuration file in an application. For example, a popular logging utility Serilog can be configured fluently, as well as from the App.config in my existing application. There are other libraries/tools that support their own configuration along with these two methods (NHibernate configuration for example). I imagined something similar for configuring vlingo.

JohnnyMaxK commented 5 years ago

Hi guys, In my opinion the source file does not matter from the moment we use the .net core configuration library that will convert the key into a string separated with : https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.2

In our examples, we can put a the configuration file vlingo actors properties and make an configuration provider for such configuration file structure. The most important is that the vlingo settings object is injected it does not matter if it comes from a configuration file.

The vlingo library must expect the vlingo settings object but must not force the configuration file name or structure.

tjaskula commented 5 years ago

@Johnny-Bee we want the configuration file be idiomatic to .net environnement. For now we have custom code that loads the configuration from the underlying file, so we don't need the provider for that.

JohnnyMaxK commented 5 years ago

I understand.

For my company, we use yaml file for the configuration.

In my opinion, we should just create a json representation of the vlingo settings object. Everything will be loaded into a flatten dictionary in the configuration object. We just have to make an extension method to build and return the vlingo settings instance from the IConfiguration. https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.2#bind-to-a-class

VaughnVernon commented 5 years ago

@Johnny-Bee Thanks for your feedback. I will make a few comments and pose questions.

I hope my perspective helps.

tjaskula commented 5 years ago

@VaughnVernon just for reference, I pointed @Johnny-Bee to this specific issue, as it may be a good start. This point is not complicated and could be a good start to get a foot on a ladder.

JSON is standard now in MS

As for the solution I was refereing to replacing the current config files to JSON files with the MS convention so we can get rid of the existing parsing code and use something like:

var config = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("config.json", optional: true, reloadOnChange: true)
    .Build();

Without going into building custom configuration providers and the like.

@zpbappi Do you confirm ?

VaughnVernon commented 5 years ago

@tjaskula @Johnny-Bee Ah, I didn't know. Sorry to get in the way. Yes, this is a great way to get into the project. Thanks for your help!

tjaskula commented 5 years ago

@VaughnVernon you do well, your questions were relevant

tjaskula commented 5 years ago

Implemented in #60