jioc 0.2.0
Dependency Injection inspired by ASP Core.
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:
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");
}
- Registered by SealabJaster
- 0.2.0 released 4 years ago
- BradleyChatha/jioc
- MIT
- Copyright © 2020, Bradley Chatha (SealabJaster)
- Authors:
- 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 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
1 downloads this month
-
581 downloads total
-
- Score:
- 0.3
- Short URL:
- jioc.dub.pm