https://github.com/pokatomnik/microdi
Deno Damn Simple Dependency Injection library
https://github.com/pokatomnik/microdi
deno dependency-injection di typescript typescript-library
Last synced: about 1 month ago
JSON representation
Deno Damn Simple Dependency Injection library
- Host: GitHub
- URL: https://github.com/pokatomnik/microdi
- Owner: pokatomnik
- License: mit
- Created: 2022-10-10T13:42:57.000Z (over 3 years ago)
- Default Branch: dungeon-master
- Last Pushed: 2024-02-16T13:50:33.000Z (over 2 years ago)
- Last Synced: 2025-10-02T11:43:56.724Z (9 months ago)
- Topics: deno, dependency-injection, di, typescript, typescript-library
- Language: TypeScript
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
```
S
M i c r o D I
a M
m P
n L
E
```
## Very Simple Dependency Injection library for [Deno](https://deno.land)
### tldr:
Provide a service:
```typescript
import { provide } from 'https://deno.land/x/microdi/Provider.ts';
class ServiceFoo {
public foo() {
console.log('Foo!');
}
}
provide(
// The service you'd like to provide
ServiceFoo,
// Service dependencies (i.e. other services)
[]
);
class ServiceBar {
public bar() {
console.log('Bar!');
}
}
provide(ServiceBar, []);
class ServiceFooBar {
public constructor(
private readonly foo: ServiceFoo,
private readonly bar: ServiceBar
) {}
}
provide(ServiceFooBar, [ServiceFoo, ServiceBar]);
class App {
public constructor(fooBar: ServiceFooBar) {}
}
provide(App, [ServiceFooBar]);
const app = resolve(App); // App!
```
### Features:
- No experimental decorators!
- Lazy initialization: services are being instantiated on the fly on demand.
- You can use a scope for your services. Just do the following:
```typescript
import { ServicesMap } from 'https://deno.land/x/microdi/ServiceStorage.ts';
const servicesMap = new ServicesMap();
class Foo {}
servicesMap.provides(Foo, []);
```
### Limitations:
- Cyclic dependencies are not supported.
- This library can instantiate services as a singletons only.
- No typechecking at dependencies
### Tests:
```
$ deno test
```