Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ahmadpayan/csharp-simple-ioc-container
A very small C# IoC container based on constructor injection.
https://github.com/ahmadpayan/csharp-simple-ioc-container
c-sharp csharp inversion-of-control inversionofcontrol ioc ioc-container learning
Last synced: about 1 month ago
JSON representation
A very small C# IoC container based on constructor injection.
- Host: GitHub
- URL: https://github.com/ahmadpayan/csharp-simple-ioc-container
- Owner: AhmadPayan
- License: mit
- Created: 2018-02-07T06:53:44.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-24T11:39:43.000Z (over 6 years ago)
- Last Synced: 2023-09-18T10:27:39.274Z (over 1 year ago)
- Topics: c-sharp, csharp, inversion-of-control, inversionofcontrol, ioc, ioc-container, learning
- Language: C#
- Homepage:
- Size: 17.6 KB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CSharp-Simple-IoC-Container
A very small IoC container in C#.NET. Just created for learning purpose.This is a simple C# Console Application that shows how you can create your own custom IoC Container in the easiest way.
**WARNING: Please do not use this as your project IoC Container, It lacks many features and functionalities.**
**Usage**
It's simple, Here are the steps:
1. Define your types and implementations.
2. Call Resolve method of the container to get desired implementation.
3. Use it!So let's get started!
**1. Register your types like as follows:**
var container = SimpleIoC.CreateInstance();
container.For().Inject();Or even simpler use Register method:
container.Register();
**2. Then resolve and get an instance of your type like this:**var resolvedService = container.Resolve();
**3. It's done! Enjoy it.**
resolvedService.SendMessage("This is a simple IoC Container!");
You can use Singleton in order to prevent instantiating classes more than once. To do so, add the **UseSingleton()** into your container:var container = SimpleIoC.CreateInstance();
container.UseSingleton();By doing this, All of the objects just creating once.