scala - Comparing Subcut and Scaldi -
i looking @ subcut , scaldi use in projects. examples provided in respective getting started documents seem similar. neither project seems provide documentation beyond getting started , scala docs.
could summarize practical differences between these frameworks in terms of features , maturity/stability. looking these packages because need able create , compose configuration dynamically @ runtime. runtime configuration main reason looking @ these libraries instead of using implicits and/or layer cake pattern di/configuration, run time configuration facilities important me. not think compiler plugins option me, both of these libraries can used without respective plugins small increase in verbosity. on scala-2.9.2 moment.
i interested in suggestions doing runtime di/configuration directly in scala, converting whole project monadic style not option me.
both libraries may pretty similar judging introductory documentation, have big differences in way how implemented. warn you, author of 1 of them (scaldi), unable make fair judgment, need take words grain of salt.
module composition , dependency graph
they have similar dsl binding, injection , way bring injector
/bindingmodule
in scope of managed class (though implicit parameter).
but containers of bindings have different ideas behind them. example in subcut class can either bound (be dependency other classes) or inject dependencies itself. but not both. if want inject in class binding, need explicitly provide (you can use current module when defining bindings within it, module not aware of kind of composition, have not found way implement cross-module dependencies in example: https://gist.github.com/olegilyenko/5623423) , don't want use concrete instances of other modules. scaldi take on problem different. each binding defined in bindingmodule
argument. can't make generically because current bindingmodule
(where defining binding) under construction , not exist yetmodule
both: can injected in other bindings , can inject other dependencies. , implicit injector
available within module when defining bindings. implicit injector represent not module defining, aware of final module composition (if decide create @ point). can separate application in several modules, , bindings within these modules can have dependencies between each other.
i think, it's biggest , important difference between 2 projects. if still not sure practically means, can recommend try both projects out , notice how restrictive subcut in respect, , how flexible scaldi's solution is.
flexibility
scaldi flexible library, allows customize part of it. of flexibility achieved though usage of type classes. example identifier
trait. subcut works directly strings , classes when comes identifies bindings. inject
method takes string
argument , you, user, can't change it. scaldi other hand uses identifier
trait instead , in places requires not identifier
, evidence canbeidentifier
type class exist particular type want use identifier. you, user, can customize treat identifier , how identifiers relate each other. class of binding identifier there no special cases.
the same idea used module composition flexible because actual composition made cancompose
type class makes sure, receive concrete injector
type out of composition (this important in case of immutable injectors. if want compose immutable injector immutable injector receive immutableinjectoraggregation
it). same reflected in other parts of library conditions , injector (i described below).
conditional bindings
conditional bindings naively supported scaldi , have not seen in other libraries. can declaratively define whether binding available or not, , when. find useful in situations distinguishing between environments (dev/test/prod). conditional bindings use type-classes, flexible well.
dynamic
from point of view, scaldi more dynamic subcut because of way injector implemented. in subcut injector collection of bindings. in scaldi it's interface has method getbinding
. means don't need know bindings upfront. integration existing di frameworks spring or guice , things properties files easy (actually scaldi provides system properties/properties file support out of box systempropertiesinjector
/propertiesinjector
, can compose own modules).
immutability
scaldi makes big distinction between mutable , immutable modules. mutable modules have more features more dynamic , error-prone. immutable modules more restrictive make easy reason about. , have choice. far know, subcut has 1 flavor can define bindings within mutable context, after you've finished defining them, it's immutable.
there many other smaller differences, hope able highlight important ones. want remind again, have insight on scaldi, facts , observations subcut, have described here, may inaccurate or invalid.
hope helps.
Comments
Post a Comment