-
Notifications
You must be signed in to change notification settings - Fork 12
-
Notifications
You must be signed in to change notification settings - Fork 12
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
API improvements for ServerEnvironment
#1315
Comments
@armiol @dmitrykuzmin how about having it shorter for the configuration phase? ServerEnvironment.when(SomeEnv.class)
.use(envType -> storageFactory())
.use(envType -> delivery()) // ... |
I personally support this change. |
@alexander-yevsyukov LGTM. |
Because of limitation of Java generics, we cannot have multiple ServerEnvironment.when(SomeEnv.class)
.use(envType -> storageFactory())
.use(envType -> delivery()) // ... We can have: ServerEnvironment.when(SomeEnv.class)
.useStorageFactory(envType -> storageFactory())
.useDelivery(envType -> delivery()) // ... Or, abandon the idea of passing functions to the Thoughts? |
Also we can have private ServerEnvironment.DeliveryFn deliveryFn(Delivery valueFromFunction) {
return t -> valueFromFunction;
} or cast it like this: when(currentType).use((ServerEnvironment.DeliveryFn) t -> valueFromFunction); This is non-trivial, to say the least, and makes things much more harder to understand. |
Summing up, I'll add |
@dmitrykuzmin, we need to expose I'm going to improve the documentation so that it's easier to understand and give it to you for review later, hopefully, this week. |
As discussed with @armiol, the following construct is problematic: ServerEnvironment.when(Staging.class).run((envType) -> configureStaging())
.when(Production.class).run((envType) -> configureProduction()); First of all, it looks as if the code under The original intent was to execute the function under To avoid the confusion, we tried to rename ServerEnvironment.ifIs(Staging.class).then((envType) -> configureStaging())
.ifIs(Production.class).then((envType) -> configureProduction()); This construct is worse than combination of two In conclusion, we're not doing the item no.3 ( |
ServerEnvironment.use(...)
should now only be usable in a context likeThat is, the
use
method won't requireEnvironmentType
as a second argument anymore (superseded bywhen(...)
), and will accept lazily-initialized values instead of plain objects. TheenvType
is the active environment type supplied for logging or other purposes.The old
use(T, EnvironmentType)
API should be deprecated.ServerEnvironment
should supply a new public methodtype()
which will return the currently activeEnvironmentType
.This way, the user code will be able to easily access the info about the currently active environment when the
ServerEnvironment
is already configured.@Internal
-ize the Environment.register(...) and improveEnvironmentType
documentation.It is not immediately apparent what exactly to do with a custom
EnvironmentType
once you've created it.For example, with the current implementation, it's possible to employ Environment.register(EnvironmentType) to register a custom env type which actually accepts some dependencies on creation which help to deduce whether it's enabled or not. And then it would be logical to check for such env presence with
when(...)
, but this would throw an exception.The text was updated successfully, but these errors were encountered: