-
Notifications
You must be signed in to change notification settings - Fork 19
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
Dependency Injection docs #51
Comments
…not be used directly. Use `require<MyClass>()` instead.
@webleaf thanks for feedback, I've made some small improvements in the docs, however IMHO all methods of Registry should be quite obvious if you have used a different DI framework before. Basically, it allows you to register class instances and get them back using Also, you can look at SimpleRegistry implementation to make it totally clear what exactly do they do - it's only a few lines of code. DependencyInjectingRegistry would also auto-create instances using constructor parameters, so that you don't need to register instances manually if there is only one implementation. As you can see from
|
Regarding the Does this answer your questions? |
@angryziber thanks for answer. Do I understand correctly that the DI container allows you to replace Constructor Injection by injecting a class directly into the body of a function and moving its configuration to a centralized storage (configuration file)? |
The Registry's here implement constructor injection. Of course, you can call constructors manually and create all the objects in the system, but the base Registry here is still useful for holding of these created objects, so that others can access them without having to know the details on how are they created (with which exactly constructor parameters). Registry is basically a generic holder of singletons in the app. |
I would like more documentation (with examples) on Dependency Injection. In what cases and how to use it correctly. Explanation of all
Registry
interface methods is required. For example, I don’t understand in what cases therequireAll()
method is needed in practice. In what cases should you usecreate()
, and in what casesregister()
? Why isoptional()
needed?I also don’t understand the meaning of this test:
klite/server/test/klite/DependencyInjectingRegistryTest.kt
Lines 21 to 30 in c85d582
In general, I need yet another small tutorial on DI. And more detailed documentation with real-life examples of your implementation.
The text was updated successfully, but these errors were encountered: