Git Product home page Git Product logo

ditranquillity's People

Contributors

adevelopers avatar cheeezcake avatar ivlevastef avatar patskovn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ditranquillity's Issues

support initializer parameters

builder.register(Card).asSelf()
.initializer { (scope, type) in
  if "gold" == type {
    return GoldCard()
  }
  if "silver" == type {
    return SilverCard()
  }
  return NormalCard()
}
.initializer { (scope) in return NormalCard() }
...
scope.resolve(Card, arg1: "gold") //GoldCard
scope.resolve(Card) //NormalCard

support lazy/owned?

class MyClass {
  private var dependency: IDependency { return lazyDependency.value }
  private let lazyDependency: DILazy<IDependency>
  init(dependency: DILazy<IDependency>) {
    self.lazyDependency= dependency
  }
  func m() {
    self.dependency.method()
  }
}
class MyClass {
  private var dependency: IDependency { return ownedDependency.value }
  private let ownedDependency: DIOwned<IDependency>
  init(dependency: DIOwned<IDependency>) {
    self.ownedDependency= dependency
  }
  func m() {
    self.dependency.method()
  }
}

Instance Per Owned

Validate recursive dependencies during build

class A { init(B b) {} } // A requires B
class B { init(A a) {} } // B requires A

builder.register(A).asSelf().initializer { 
  (scope) in A(scope.resolve(B)) 
}
builder.register(B).asSelf().initializer { 
  (scope) in B(scope.resolve(A)) 
}

Change syntax

resolve("name") + arg to resolve(Name: "name") + arg
for clarity

integrate with ViewControllers

Create DIViewController for override init methods for supported resolve object for ViewController.
Also supported warnings if parent UIViewController (not DIViewController)
also UINavigationController

support + validate multiple implementations during build


builder.register(A1).asType(AProtocol)
builder.register(A2).asType(AProtocol)
builder.register(A3).asType(AProtocol)
do {
builder.build() // throw exception: A1,A2,A3 implementation one protocol AProtocol setup default
} catch {
}

Need supported multimap for checked current case

support inject

class MyClass {
  private let dependency: IDependency
  public init(dependency: IDependency) {
    self.dependency = dependency
  }
}

Supported resolveMany into initializer

See Logger example.

changes:
resolveMany:
for rType in rTypes {
let pair = RTypeWithNamePair(rType, "")
if !recursive.contains(pair.uniqueKey) {
try result.append(resolveUseRType(scope, pair: pair , method: method))
}
}

support Modules

class MyModule: Module {
  func registate(builder: ComponentBuilder) {
  }
}
builder.registrate(MyModule)

create dependency syntax

It's no initializer!

builder.register(Inject).dependency("logger", LoggerProtocol).dependency("service", ServiceProtocol)

builder.register(Inject).dependency{ (scope, inject) in 
  inject.logger = scope.resolve(LoggerProtocol)
  inject.service = scope.resolve(ServiceProtocol)
}

support register asName

register(UIViewController).asName(pattern: "mainVC").initializer(return MainVC())
register(UIViewController).asName(pattern: "secondVC").initializer(return SecondVC())
class Inject {
  setMain(mainVC: UIViewController) {..}//it's MainVC()
  setSecond(secondVC: UIViewController) {...} //it's SecondVC()
}
...
inject.setMain(scope.resolve("mainVC"))
inject.setSecond(scope.resolve("secondVC"))

support Any Type

builder.registrate(Int).asName("*constName").initializer {_ in 20 }
builder.registrate(Array).asName("constName{Arr|Array}").initializer { _ in [1,2,3,4] }
let constName: Int
let constNameArr: [Int]
init(constName: Int, constNameArr: [Int], secondConstName: Int) {//20, [1,2,3,4], 20
  self.constName = constName
  self.constNameArr = constNameArr
}

supported parent

let modificator = Modificator()
.asType(Logger.self)
.instanceSingle()

builder.register{ ConsoleLogger() }
.use(modificator: modificator)

builder.register{ FileLogger(file: "file.log") }
.use(modificator: modificator)

builder.register{ ServerLogger(server: "http://server.com/") }
.use(modificator: modificator)

builder.register{ MainLogger(loggers: **!$0) }
.use(modificator: modificator)
.asDefault()

support lifetime perApp

buider.registrate(Settings).asSelf().constructor(...).instancePerApp()
class Settings {
  var userColor: String { didSet { save() } }

  func init() {
    userColor = "LoadFrom"
  }

  func save() {
    "SaveTo" = userColor
  }
}

support thread scope

m() {
  let thread1scope = ScopeFabric.createScope()
  thread1scope.bindToThread() // scope bind to thread1
  //or let thread1scope = ScopeFabric.createThreadScope() // scope bind to thread1
  defer {
    thread1scope.unbindFromThread() //scope unbind from thread 1
  }

  let threadScope = ScopeFabric.currentThreadScope() // return thread1scope
  dispatch_async(dispatch_get_other, {
    thread1scope.bindToThread() //scope bind to thread 2
    m1()
    thread1scope.unbindFromThread() //scope unbind from thread 2
  })
 m2()
}
m() {
  let thread1scope = ScopeFabric.createScope()
  thread1scope.bindToThread { (scope) in //bind to thread1
    dispatch_async(dispatch_get_other, {
      scope.bindToThread {
        m1()
      }
   })
   m2()
 } //unbind from thread1
}

support ImplicitlyUnwrappedOptional

For DI Implicitly Unwrapped Optional better suited Normal Optional, because this property contains all the time value, but the value initialized after init method.

added logger

protocol logger {
register(...)
resolve(...)
warning(...)
error(...)
}

support new timelifes

Single/ LazySingle
Для DIStoryboard можно будет указывать какие viewController (по идентификатору) нужно сохранять

improved detect optional

protocol DIBaseType {
func getBaseType() -> Any
}
extension AnyClass: DIBaseType {
}
extension Optional: DIBaseType {
}
extension ImplicityUnwrapperOptional: DIBaseType {
}

support package registration types

For example:

builder.registerAny("*Service").asOwn().asTypes("*ServiceProtocol").instancePerScope()

builder.registerAny(UIViewController)
  .asName("firstVC", FirstViewController)
  .asName("secondVC", SecondViewController)
  .asType(ThirdViewController)
  .instancePerDependency()

support parameters for viewController

added method performSegueWithIdentifier(identifier, sender:, arg:)
added method instantiateViewControllerWithIdentifier(identifier, arg:)
added method instantiateViewController(arg:) -> T (auto found identifier?)

supported by registration instancePerRequest(), method
perRequestParams{ (obj, arg1, arg2) in obj.arg1 = arg1 ... }

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.