basics.rb |
|
|---|---|
|
Silent killer of dependencies and configs Micon allows You easilly and transparently eliminate dependencies and configs. Usually, when You are building complex system following tasks should be solved:
By component I mean any parts of code logically grouped together. Micon solves all these tasks automatically, and has the following price – You has to:
That’s all the price, not a big one, compared to the value, eh? It’s all You need to know about it to use 95% of it, there are also 2-3 more specific methods, but they are needed very rarelly. Techincally Micon is sort of Dependency Injector, but because of its simplicity and invisibility it looks like an alien compared to its complex and bloated IoC / DI cousins. Install Micon with Rubygems:
Once installed, You can proceed with the examples below. The project hosted on GitHub. You can report bugs and discuss features on the issues page. |
|
Basic example |
require 'micon'
require 'logger' |
|
Registering |
micon.register(:logger){Logger.new STDOUT}
class Application |
|
Whiring the |
inject logger: :logger |
|
Now You can use |
def run
logger.info 'running ...'
end
end |
|
Running our application, type:
And You should see in the console something like this:
|
Application.new.run |
Advanced example |
|
|
It’s hard to see advantages of Dependency Injection using trivial example, so this example is more complicated. Let’s pretend that we are building the Ultimate Web Framework, RoR Killer. There will be lot’s of modules and dependencies, let’s see how Micon can eliminate them. We build our framework in two steps:
You can compare these two examples and see advantages of using Dependency Injection. |
|