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:

Manual usage
Put the following dependency into your project's dependences section:

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

  • 0 downloads this week

  • 0 downloads this month

  • 580 downloads total

Score:
0.3
Short URL:
jioc.dub.pm