jioc 0.2.0

Dependency Injection inspired by ASP Core.


To use this package, run the following command in your project's root directory:

Overview

This library was inspired by ASP Core's Dependency Injection.

The ServiceProvider class can be used as the Service Locator and/or the Constructor Injection patterns.

The Injector class can also inject values into a function call, as well as perform constructor injection on structs (whereas ServiceProvider is limited to classes).

Expect bugs for the time being, but please don't be afraid to open an issue on Github if you come across a bug, issue, or want to suggest and improvement.

Usage

More fleshed out README to come soon (TM).

TL;DR

import jaster.ioc;

interface IPasswordMatcher
{
    bool isValidPassword(string pass);
}

class PasswordMatcher : IPasswordMatcher
{
    bool isValidPassword(string pass)
    {
        return pass == "dlang #1";
    }
}

class LoginService
{
    private IPasswordMatcher _matcher;

    this(IPasswordMatcher matcher)
    {
        this._matcher = matcher;
    }

    void signup(string password)
    {
        assert(this._matcher.isValidPassword(password));
    }
}

void main()
{
    auto services = new ServiceProvider(
    [
        ServiceInfo.asSingleton!(IPasswordMatcher, PasswordMatcher),
        ServiceInfo.asScoped!LoginService
    ]);

    auto loginService = services.defaultScope.getServiceOrNull!LoginService();
    loginService.signup("dlang #1");
    loginService.signup("crash me baby");
}
Authors:
  • Bradley Chatha (SealabJaster)
Dependencies:
none
Versions:
0.2.0 2020-Feb-24
0.2.0-beta.1 2020-Feb-17
0.1.0-beta.3 2019-Aug-14
0.1.0-beta.2 2019-Aug-14
0.1.0-beta.1 2019-Aug-11
Show all 6 versions
Download Stats:
  • 0 downloads today

  • 2 downloads this week

  • 34 downloads this month

  • 101 downloads total

Score:
0.7
Short URL:
jioc.dub.pm