Comments (3)
Hi. Thanks for your questions!
Isn't .inSomeScope() more error prone then ditox's {scope:"some"} argument?
You’re right. However, I can say “warning prone” rather than “error prone”.
I’m thinking about how to improve the DX of Brandi. Ditox’s approach looks great, I may will to implement a similar approach with a compile-time check.
Your approach for declaring injection gives people ability to declare it in place of Class declaration thus might lead to mix up DI and services.
You can call injected
in any place of your app. Yes, it’s better to split class declaration and injecting, and inject near a container configuration. I’ll fix examples in documentation.
Your tag based conditional injection is a great idea! Do you think factory based instance generation is a little bit more flexible?
Thank you
from brandi.
Your idea about instance generation is not clear to me. Can you give an example?
// Define tokens for injections.
// Token can be optional to provide default values.
const TOKENS = {
service: token<ServiceInterface>('Token description for debugging'),
};
const TAGS = {
tag1: token<'val1' | 'val2'>('Token description for debugging'),
};
// Create the container.
const container = createContainer();
// Provide a value to the container.
container.bindValue(TAGS.tag1, 'val1')
// Dynamic values are provided by factories.
container.bindFactory(
TOKENS.service,
injectable((tag: 'val1' | 'val2') => tag === 'val1' ? new Service() : new MockService(), TAGS.tag1),
);
from brandi.
Hello! As the author of Ditox.js, I'm happy to meet a library that shares similar concepts. It's interesting that although the development of both libraries was started around the same time, and different design decisions were applied, but the APIs share similar features and ideas. This allows to hope that the implemented APIs will be quite stable in the long run.
As for the functionality of the libraries - they differ in detail. For example, Ditox.js doesn't have capture()
and restore()
or "conditional bindings", because I think container is supposed to be a super simple thing and configuration by tags can be emulated by factories. Also, modules are described in different ways: declaratively in Ditox.js and imperatively in Brandi.
from brandi.
Related Issues (10)
- Add async factories support HOT 3
- Calling injected with a token instead of constructor HOT 2
- Please update react types HOT 1
- Unable to get instance at runtime - what am i missing? HOT 4
- Accept token factories as arguments to `injected` HOT 2
- Constructor injection for factories with arguments HOT 3
- Injected not working when disabled strictNullChecks HOT 1
- Array Injections HOT 4
- DIP Violation HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from brandi.