danidiaz / dep-t

Dependency injection for records-of-functions.
http://hackage.haskell.org/package/dep-t
BSD 3-Clause "New" or "Revised" License
8 stars 2 forks source link

The problem of initialization #36

Open danidiaz opened 1 year ago

danidiaz commented 1 year ago

Inspired by this comment in the Haskell Discourse.

It feels natural that a "constructor" could have effects, performing some initialization on the component, initialization which might use functionality from the component's dependencies. Think the PostConstruct annotation in Java.

In dep-t, one style of initializers is supported, but there are some catches:

Possible solutions:

danidiaz commented 1 year ago

Spring bean creation lifecycle : Why having multiple interaction points?

BeanFactoryPostProcessor and PriorityOrdered.

BeanFactoryPostProcessor beans that are autodetected in an ApplicationContext will be ordered according to PriorityOrdered and Ordered semantics. In contrast, BeanFactoryPostProcessor beans that are registered programmatically with a ConfigurableApplicationContext will be applied in the order of registration; any ordering semantics expressed through implementing the PriorityOrdered or Ordered interface will be ignored for programmatically registered post-processors. Furthermore, the @Order annotation is not taken into account for BeanFactoryPostProcessor beans.

danidiaz commented 1 year ago

See also

danidiaz commented 1 year ago

Moving to a more registry way of doing things, with constructors that use positional parameters instead of Has, would make functions like lmapConstructor (useful to install named loggers) more difficult to implement.

I also kinda dislike positional parameters for dependencies and would prefer to keep using Has.