DI container, Inverse of Control

About Monkey 2 Forums Monkey 2 Code Library DI container, Inverse of Control

This topic contains 2 replies, has 2 voices, and was last updated by  mac767 1 year, 2 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #14079


    Hi. I wrote IoC-container (inverse of control) that helps us incapsulate creation of new instances.

    It named Di to be short, that mean dependancy inversion.

    This container stores bindings of type T1,T2,.. with their realization.

    You can bind interface type with its concrete realization.

    The goal is to reduce creation of instances by New and use container instead.

    Short example:

    Yes, you must create all these Game, Metrica, Logger – but in special place, not in your business logic.

    Important: Di store reference to functions, that will create our realization. If you don’t call, for example Di.Resolve then realization of ISomeModel will not be created at all.

    It may be profit – if realization isn’t cost-free of resources etc.

    But the main profit is – you can access needed instances in any place of your app w/o worrying about what params you should pass into constructor.

    And if you need to change realization – you can change the only place where you setup container and it’ll change all of places where it used.

    Ok, there is a code with 2 exaples.

    And separated Di class:



    I created repository for that:


    Repository contains core class di.monkey2  and two demo programs.

    Also I changed code above – FuncWrapper was removed.

    PS: such containers are suitable for apps, and much less for games.



    Hi nerobot,

    very useful for clean code in large projects.
    Thanks for sharing.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.