Giter VIP home page Giter VIP logo

Comments (3)

vovaspace avatar vovaspace commented on May 25, 2024

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 🙏. Your idea about instance generation is not clear to me. Can you give an example?

from brandi.

BANOnotIT avatar BANOnotIT commented on May 25, 2024

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.

mnasyrov avatar mnasyrov commented on May 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.