https://github.com/nklbdev/simplestioccontainercsharp
Just simplest IoC container on C#
https://github.com/nklbdev/simplestioccontainercsharp
Last synced: about 1 year ago
JSON representation
Just simplest IoC container on C#
- Host: GitHub
- URL: https://github.com/nklbdev/simplestioccontainercsharp
- Owner: nklbdev
- Created: 2015-08-11T07:13:35.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-10-23T13:17:29.000Z (over 7 years ago)
- Last Synced: 2025-01-23T09:33:07.687Z (over 1 year ago)
- Language: C#
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SimplestIocContainerCSharp
Just simplest IoC container on C#
This container is not thread-safe.
Usage:
```c#
public interface IGod
{
string Attack();
}
public interface IWeapon
{
string Hit();
}
public class Thor : IGod
{
private readonly IWeapon _weapon;
public Thor(IWeapon weapon)
{
if (weapon == null)
throw new ArgumentNullException(nameof(weapon));
_weapon = weapon;
}
public string Attack()
{
return _weapon.Hit();
}
}
public class Mjolnir : IWeapon
{
public string Hit()
{
return "BADABOOM!!!";
}
}
class Program
{
static void Main(string[] args)
{
var container = new Container()
.Bind(() => new Mjolnir())
.Bind(c => new Thor(c.Resolve()));
var god = container.Resolve();
Console.WriteLine(god.Attack());
Console.ReadLine();
}
}
```
will print:
BADABOOM!!!
You can use key object instead type parameter or specify single or multiple instance binding.