jioc 0.2.0-beta.1

An inversion of control library.


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

Very brief, quickly made overview

Modeled after ASP Core's Dependency Injection.

Expect bugs.

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