Open blacktooth opened 6 years ago
Well, if you have an instance of UserModule
, simply userModule.userFinder
?
Well, if you have an instance of
UserModule
, simplyuserModule.userFinder
?
Getting an instance of UserModule
might involve instantiating multiple other modules which can become very long. Something like,
new UserModule(new DataBaseConnectionModule(new HttpConnectionModule(new URLModule(), new ThrottlingLimitsModule(), new TimeoutsModule()))))
Yes, well, that might need a second level of wiring :) But you need to create those instances at some point ...
Have you considered how Guice solves this problem using the install
method? One can define a module that combines everything,
class DatabaseConnectionModule {
install(new URLModule())
install(new TimeoutsModule())
install(new ThrottlingModule())
val databaseConnection = ...
}
class UserModule {
install(new DataBaseConnectionModule())
val userFinder: UserFinder = ...
}
class AppModule {
install(new UserModule())
install(new BillingModule())
}
val wired = wiredInModule(new AppModule())
val userFinder: UserFinder = wired.lookup(classOf[UserFinder])
What is your opinion on this?
I think you can do the same using a module which uses wire
to wire other modules, with compile-time safety.
I am new to Scala and Macwire and trying to figure out how to access instances that are wired using modules organized as classes. If modules are defined as traits, one can extend them and access the wired instances in them as below,
If my modules are organized as classes with composition, how do I access the instances?