GithubHelp home page GithubHelp logo

buluozhiri / swiftsuspenders Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tschneidereit/swiftsuspenders

0.0 1.0 0.0 3.11 MB

NOTE: Find the offical repo at http://github.com/robotlegs/swiftsuspenders

Home Page: https://github.com/robotlegs/swiftsuspenders

License: MIT License

swiftsuspenders's Introduction

SwiftSuspenders

Attention: This README is just a stub to prevent you from reading the heavily outdated one for Swiftsuspenders 1.x.

That being said, here's a very quick outline of the new version's capabilities and API:

Features

  • injection requests configurable using standardized metadata
  • can inject into vars, setters, methods and constructors
  • injection requests can be optional
  • mapping dependencies by class and, optionally, name
  • satisfying dependencies using value, class instance, singleton or custom providers
  • chaining multiple injectors to create modular dependency-mapping graphs much like inheritance works in OOP
  • defining local and shared scope for mappings, akin to public and private members of a class
  • defining soft mappings that only get used if no injector higher up in the inheritance chain can satisfy a dependency
  • support object live-cycle management (note: The latter part of that management, i.e. the destruction, is not yet implemented, but will be for 2.0 final)

API

Requests

Requests, aka injection points, can be defined using the metadata tag [Inject] atop the var, setter or method to inject into. For constructor injection, no metadata is required.

Named injections can be defined using the syntax [Inject(name="injection name")]. In this case, constructors have to have their metadata placed atop the class itself, not the constructor. This is a limitation of the Flex compiler.

Optional injection requests can be defined using the syntax [Inject(optional=true)]

Mappings

The API is expressed as a DSL to make very fine-grained configuration of each mapping easy and readable:

const injector : Injector = new Injector;

//create a basic mapping:
injector.map(Sprite); //will instantiate a new Sprite for each request for Sprite

//map to another class:
injector.map(Sprite).toType(BetterSprite); //will instantiate a new BetterSprite for each request for Sprite

//map as a singleton:
injector.map(EventDispatcher).asSingleton(); //will lazily create an instance and return it for each consecutive request

//map an interface to a singleton:
injector.map(IEventDispatcher).toSingleton(EventDispatcher);

Beta

So, that's it for now as far as documentation is concerned. The implementation, on the other hand, is very stable and shouldn't regress anything that used to work in 1.x, as long as the API changes are dealt with, of course.

More documentation will soon come here, in the github wiki and as asdocs.

swiftsuspenders's People

Watchers

James Cloos avatar

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.