All Projects → microsoft → Minioc

microsoft / Minioc

Licence: mit
Single-file minimal C# IoC container

Programming Languages

csharp
926 projects

Projects that are alternatives of or similar to Minioc

brisk-ioc
fast light brisk ioc/di container on nodejs; Node下快速 轻量的IoC/DI容器,依赖注入,配合装饰器使用
Stars: ✭ 12 (-83.1%)
Mutual labels:  lightweight, ioc, ioc-container
Ioc
🦄 lightweight (<1kb) inversion of control javascript library for dependency injection written in typescript
Stars: ✭ 171 (+140.85%)
Mutual labels:  lightweight, ioc, ioc-container
Singularity
A extremely fast ioc container for high performance applications
Stars: ✭ 63 (-11.27%)
Mutual labels:  ioc, ioc-container
DependencyInjector
Lightweight dependency injector
Stars: ✭ 30 (-57.75%)
Mutual labels:  ioc, ioc-container
Poodinis
A dependency injection framework for D with support for autowiring.
Stars: ✭ 57 (-19.72%)
Mutual labels:  ioc, ioc-container
SwiftInjection
Dependency Injection framework for Swift
Stars: ✭ 21 (-70.42%)
Mutual labels:  ioc, ioc-container
inject
[Archived] See https://github.com/goava/di.
Stars: ✭ 49 (-30.99%)
Mutual labels:  ioc, ioc-container
tsioc
AOP, Ioc container, Boot framework, unit testing framework , activities workflow framework.
Stars: ✭ 15 (-78.87%)
Mutual labels:  ioc, ioc-container
iocgo
A lightweight Inversion of Control (IoC) (Dependency Injection) container for Golang
Stars: ✭ 36 (-49.3%)
Mutual labels:  ioc, ioc-container
Ecsrx
A reactive take on the ECS pattern for .net game developers
Stars: ✭ 288 (+305.63%)
Mutual labels:  ioc, ioc-container
Kangaru
🦘 A dependency injection container for C++11, C++14 and later
Stars: ✭ 297 (+318.31%)
Mutual labels:  ioc, ioc-container
Reflex
Minimal dependency injection framework for Unity
Stars: ✭ 263 (+270.42%)
Mutual labels:  ioc, ioc-container
containerx
⚡简单的Java依赖注入框架,代码量少,实现了依赖注入和AOP。适合Spring源码的初学者掌握其核心原理
Stars: ✭ 76 (+7.04%)
Mutual labels:  ioc, ioc-container
di
🛠 A full-featured dependency injection container for go programming language.
Stars: ✭ 156 (+119.72%)
Mutual labels:  ioc, ioc-container
vesselize
⛵ A JavaScript IoC container that works seamlessly with Vue.js and React.
Stars: ✭ 22 (-69.01%)
Mutual labels:  ioc, ioc-container
ThunderboltIoc
One of the very first IoC frameworks for .Net that has no reflection. An IoC that casts its services before thunder casts its bolts.
Stars: ✭ 40 (-43.66%)
Mutual labels:  ioc, ioc-container
Typescript Ioc
A Lightweight annotation-based dependency injection container for typescript.
Stars: ✭ 427 (+501.41%)
Mutual labels:  ioc, ioc-container
ashley
Ashley is a dependency injection container for JavaScript.
Stars: ✭ 23 (-67.61%)
Mutual labels:  ioc, ioc-container
alpha-dic
Powerful dependency injection container for node.js
Stars: ✭ 27 (-61.97%)
Mutual labels:  ioc, ioc-container
Summer
这是一个支持分布式和集群的java游戏服务器框架,可用于开发棋牌、回合制等游戏。基于netty实现高性能通讯,支持tcp、http、websocket等协议。支持消息加解密、攻击拦截、黑白名单机制。封装了redis缓存、mysql数据库的连接与使用。轻量级,便于上手。
Stars: ✭ 336 (+373.24%)
Mutual labels:  ioc, ioc-container

MinIoC

MinIoC is a single-file, minimal C# IoC container. While there are several great IoC solutions available which are much more powerful and flexible, MinIoC aims to enable lightweight/small-footprint projects with a simple implementation. It is distributed as a single .cs file which can be included and compiled in other projects.

Build status

Example

var container = new Container();

container.Register<IFoo>(typeof(Foo));
container.Register<IBar>(() => new Bar());
container.Register<IBaz>(typeof(Baz)).AsSingleton();

/* ... */

var baz = container.Resolve<IBaz>();

The example above calls the generic Register<T>(Type) and Register<T>(Func<T>) methods. The first one binds the generic parameter type to an actual type, the second binds the generic parameter type to a factory function. Calling Resolve<T>() creates an instance of the registered type.

For a type binding, the container uses the actual type's first constructor. All arguments need to also be resolvable by the container.

API Details

The container implements IServiceProvider, exposing an object GetService(Type type) method and two non-generic registration methods: Register(Type @interface, Func<object> factory) and Register(Type @interface, Type implementation).

Generic extension methods are provided both for registration (Register<T>(Type), Register<T>(Func<T>), Register<T>()) and resolution (T Resolve<T>()).

Lifetimes

By default, each call to Resolve<T>() creates a new instance. Two other object lifetimes are supported: singleton and per-scope.

A singleton is created by calling AsSingleton() after registration:

container.Register<IFoo>(typeof(Foo)).AsSingleton();

var instance1 = container.Resolve<IFoo>();
var instance2 = container.Resolve<IFoo>();

Assert.AreEqual(instance1, instance2);

Scopes allow finer-grained lifetime control, where all types registered as per-scope are unique within a given scope. This allows singleton-like behavior within a scope but multiple object instances can be created across scopes. Scopes are created by calling CreateScope() on a contianer instance and they also implement IServiceProvider, exposing an object GetService(Type type) method (and a Resolve<T>() extension method):

container.Register<IFoo>(typeof(Foo)).PerScope();
  
var instance1 = container.Resolve<IFoo>();
var instance2 = container.Resolve<IFoo>();

// Container is itself a scope
Assert.AreEqual(instance1, instance2);

using (var scope = container.CreateScope())
{
    var instance3 = scope.Resolve<IFoo>();
    var instance4 = scope.Resolve<IFoo>();

    // Instances should be equal inside a scope
    Assert.AreEqual(instance3, instance4);
    
    // Instances should not be equal across scopes
    Assert.AreNotEqual(instance1, instance3);
}

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].