Giter Club home page Giter Club logo

dependency-locator's People

Contributors

marcel-valdez avatar

Watchers

 avatar  avatar

dependency-locator's Issues

Dynamic implementation change by means of proxies

Add a feature to change an interface's implementation at runtime.

This can be done by returning a PROXY to the implementation when an interface's implementation object is created, and when you want to change an object's implementation three things have to happen:

  1. The proxy object calls a 'Stop' method on the implementing object
  2. The implementing object returns its 'Memento object'
  3. A instance of the new implementation is created, and its 'Start' method is called with the previous 'Memento object' as a parameter.

Example

// 1. At some point the client side
var myService = locator.Create<IService>();
// this produces valid results
result = myService.Action();
// ...
// 2. Some other place in the client side
locator.ReloadDependencies();
// ...
// 3. In the proxy's code, in parallel preferably
void changeImpl(IService newImpl) {
  object memento = this.impl.Stop();
  newImpl.Start(memento);
  this.impl = newImpl;
}
// ...
// 4. At some point in the client side again
// this produces valid results
result = myService.Action();

Use a Dependfile for dependencies configuration

Using csharp as a script, configure the implementations of -interface components-.
Important details

  • Use convention over configuration:
    Automatically map implementations to interfaces, unless otherwise stated.
  • This script must NOT be compiled, it is loaded in runtime.
  • The name Dependfile is the -default- name for this script, unless otherwise stated.

Example Dependfile

// Default implementations
Interfaces("Interfaces.dll").ImplementedBy("Implementations.dll");

// Explicit implementations alternatives
// 1.
Setup.Interface<IService>().ImplementedBy<Service>();
// 2.
using(var iface = Interfaces("Interfaces.dll"))
using(var impl = Implementations("Implementations.dll")) {
  Interface<IService>(iface).ImplementedBy<Service>(impl);
}
// 3
using(var iface = Interfaces("Interfaces.dll"))
using(var impl = Implementations("Implementations.dll")) {
  iface.Dependency<IService, Service>(impl);
}
// 4
Interface<IService>("Interfaces.dll").ImplementedBy<Service>("Implementation.dll");

The script needs to identify, at runtime the type IService and Service, because there is no "using"

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.