Coder Social home page Coder Social logo

ninject / ninject.extensions.dependencycreation Goto Github PK

View Code? Open in Web Editor NEW
6.0 10.0 1.0 20.31 MB

This module is used to create a dependency toghether with another object without having a reference to it.

License: Other

Shell 7.04% C# 92.96%

ninject.extensions.dependencycreation's Introduction

This module is used to create a dependency toghether with another object without having a reference to it. It is used to completely decouple components and is normaly used togetter with an event broker for comunication between these components. 

Example:
this.kernel.Bind<IParent>().To<Parent>();
this.kernel.DefineDependency<IParent, Dependency>();
this.kernel.Bind<Dependency>().ToSelf().InCreatorScope();

Parent parent = this.kernel.Get<Parent>();

This will create the Dependency togetter with the Parent. And they will both be destroyed when parent is collected by the garbage collector. Normally, you would attach them both to an event broker so that they can communicate without knowing each others existence for complete decoupling of these components.

Passing the creator to the dependency
-------------------------------------
There are some very rare cases where the dependency gets created before the one using them. E.g. there are UI frameworks that create the view automatically but because a MV(V)P should be used the presenter has to be created with the view and the view needs to be passed:

this.kernel.Bind<View>().ToSelf();
this.kernel.DefineDependency<View, Presenter();
this.kernel.Bind<Presenter>().ToSelf().WithCreatorAsConstructorArgument("view").InCreatorScope();

public class Presenter
{
    private IView view;
	public Presenter(IView view) { this. view = view; }
}

This will create a new Presenter whenever a new View is created and passes the view into the presenter using the given parameter name ("view"). Note that the presenter will get a proxy to the view which forwards all calls to the view. The proxy has only a weak reference to the view in order that the view can be released.

NOTE: Only use this if you can't create the presenter first. Try all to change the creation order. This is only the last way if you can't influence the creation order.

ninject.extensions.dependencycreation's People

Contributors

iappert avatar remogloor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

dut3062796s

ninject.extensions.dependencycreation's Issues

Castle.Core dependency

I think that the wrong version of Castle.Core is referenced. At least, not the same as the other extensions use.

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.