aermicioi.aedi

Aedi, a dependency injection library.

Aedi is a dependency injection library. It does provide a set of containers that do IoC, and an interface to configure application components (structs, objects, etc.)

$(BIG $(B Aim: ))

The aim of library is to provide a dependency injection solution that is feature rich, easy to use, easy to learn, and easy to extend up to your needs.

$(BIG $(B Why should it be used: ))

  • Decouples components in your application.
  • Decreases hassle with application components setup (wiring and creation)
  • Increases code reusability (since no dependencies are created in dependent objects.)
  • Allows easier to test code that is dependent on other components
  • Eases the implementation single responsibility principle in components

$(BIG $(B When should it be used: ))

  • When an application has to be highly configurable.
  • When an application has a high number of interdependent components.
  • When doing unit testing of highly dependent components.

$(BIG $(B How should it be used: ))

It's simple:

  • Create a container
  • Register an application component. Any data (struct, object, union, etc) is treated as application component.
  • Write a wiring configuration
  • Repeat process for other components.
  • Boot container

First of all a container should be created:

SingletonContainer container = new SingletonContainer;

Container is responsible for storing, and managing application's components.

Next, register component into container:

container.register!Color

Component is registered by calling .register method on container with type of component. Note, that in example we do not end the statement. That's because component should be configured next:

.set!"r"(cast(ubyte) 250)
.set!"g"(cast(ubyte) 210)
.set!"b"(cast(ubyte) 255);

.set method configures component properties to specific values (setter injection in other words). Note the example ends in ; which means that it's end of statement and Color registration/configuration. Once components are registered and configured, container needs to be booted (instantiated):

container.instantiate();

Container during boot operation, will do various stuff, including creation and wiring of components between them. It's important to call container.instantiate() after all application's components have been registered into container, otherwise it is not guaranteed that application will work correctly.

Once container is booted, components in it are available for use. To fetch it use locate method like in following example:

container.locate!Color.writeln;

Try running the minimal example from examples folder, the output of example will be the Color that was registered in container:

Color is:	Color(250, 210, 255)

Modules

configurer
module aermicioi.aedi.configurer

This module provides a set of interfaces used to register objects, into containers/containers (singleton, prototype, etc.) as well as other data.

container
module aermicioi.aedi.container

Defines interface for objects that are able to instantiate and manage lifetime for instantiated objects. Provides a singleton, and prototype implementation of defined interface.

exception
module aermicioi.aedi.exception

A set of exceptions used across the library.

factory
module aermicioi.aedi.factory

The package provides a set interfaces that standardise the implementation of Factory objects. It provides as well a basic set of such objects.

storage
module aermicioi.aedi.storage

The purpose of package, is to provide common interface for locating, storing, aliasing of object. It does provide interface for objects that are implementing service locator pattern.

Public Imports

aermicioi.aedi.exception
public import aermicioi.aedi.exception;
Undocumented in source.
aermicioi.aedi.configurer
public import aermicioi.aedi.configurer;
Undocumented in source.
aermicioi.aedi.factory
public import aermicioi.aedi.factory;
Undocumented in source.
aermicioi.aedi.container
public import aermicioi.aedi.container;
Undocumented in source.
aermicioi.aedi.storage
public import aermicioi.aedi.storage;
Undocumented in source.

Meta

License

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following:

The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Authors

Alexandru Ermicioi