sithmel / diogenes Goto Github PK
View Code? Open in Web Editor NEWA dependency injection framework
License: MIT License
A dependency injection framework
License: MIT License
There should be something in place to automatically cache a service when dependency are unchanged
The goal of this release is to focus on using diogenes as dependency injection framework.
Version 1 relies on an asynchronous caching mechanism.
It was complicated to implement and also useless. Furthermore the cached value should be JSON serializable which is pretty stupid for a library used for dependency injection (for example you can't cache an object instance or a function).
So I need to:
I'd like to cut any dependency from async-deco (maybe I would use the log).
Event system is something should be implemented outside of diogenes:
Other improvements:
Lastly I'd like to enphasize in the documentation that it is a dependency injection framework, not a library for dealing with asynchronicity.
Example:
registry.service(function example (deps) {
...
});
Would be the equivalent of:
registry.service('example').provides(function (deps) {
...
})
Also:
registry.service(function example (deps) {
...
})
.dependsOn([ref1, ref2]);
With ref1 ref2 as real functions rather than strings.
Maybe also an alternative shorthand:
registry.service([ref1, ref2], function example (deps) {
...
})
and a curried version to use as decorator
@registry.addService([ref1, ref2])
function example (deps) {
...
}
it should be easy doing something like:
function example() {
/**
Some text
**/
...
}
/\/\*\*(.+?)\*\*\//.exec(example.toString())
Extra goal: add markdown2html to diogenes-lantern
Some graphic representation of the graphs can help understand how the system work
Adding a system to invalidate the cache of a service:
Now if a configuration doesn't match any service, occamsrazor throws an exception.
There may be cases in which I don't need a service at all, so no need of complaining.
It should be possible to add extra deps while running:
registry.run('hello', { world: 'world' })
I had a few thoughts about diogenes API. The trigger for all of them was the use of decorators.
I really think that the decorator pattern fits particularly well in diogenes. You can enhance a service with caching/logging and many different features (just open async-deco and see how many things can be done).
Some of the current features don't fits well if you use this pattern, basically all features relying in introspecting the functions for its name and arity.
So I propose this set of changes:
cons
pros
I used the arity of the function to guess if the service is callback based. But the decorator won't have the same arity. All my decorators for example use "arguments".
cons
I think we might need to define services with callbacks frequently, especially migrating from old code.
pros
it can be fixed easily using promisify (doh another decorator)
As a side note I would like to know what do you think about adding a special feature to define and compose decorators in diogenes.
I was thinking of something like
diogenes
.service('myservice')
.provides([cache, promisify, myservice])
// or .provides(cache, promisify, myservice)
equivalent to:
diogenes
.service('myservice')
.provides(cache(promisify(myservice)))
but it can be just as good doing:
@cache
@promisify
function myservice() {
...
}
diogenes
.service('myservice')
.provides(myservice)
But the decorator specs are still in discussion ....
What's your thoughts @framp @mikeryancodes
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.