Question: Good practices for app config when using Aff/Eff #1206
-
I'm stating to have a play around with the Aff and Eff types that take a runtime and was hoping someone could give me some opinions on good way to handle config across an application. Say we have some service in our application that takes some config as a dependency: public class CustomerService
{
private readonly CustomerServiceConfig _config;
...
} If I wanted to add this config to a runtime that I can use with I feel like option 2 would be nicer in theory as then only the config that's needed for the current service is accessible, but it would mean defining a lot of interfaces, traits and static accessor classes. On the other hand, option 1 would mean only one interface, trait and accessor class but having all of the config available to every consumer feels like a smell. Are there some other approaches I could try out? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Both option 1 and 2 are fine, it really depends how much config you have. Remember you can inherit traits (because they're just interfaces), so you can have: public interface HasAppConfig<RT> { ... }
public interface HasServiceConfig<RT> { ... }
public interface HasWebConfig<RT> { ... } And then package them up with inheritance: public interface HasConfig<RT> :
HasAppConfig<RT>,
HasServiceConfig<RT>,
HasWebConfig<RT>
{} That means you can use The other thing to remember is to only expose configuration that's not related to the underlying implementation(s) of any trtait. For example, if you had a The key reasoning behind this is that you don't want implementation details leaking into your runtime. It's there to be an abstract representation of IO. You shouldn't know whether the database you're 'connecting to' is SQL Server, or some in-memory solution. |
Beta Was this translation helpful? Give feedback.
Both option 1 and 2 are fine, it really depends how much config you have. Remember you can inherit traits (because they're just interfaces), so you can have:
And then package them up with inheritance:
That means you can use
HasConfig
in general areas of the application, andHas*
in more specific areas, like a service-subsystem.The other thing to remember is to only expose configuration that's not related to the underlying i…