-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the IfInjector wiki. IfInjector is a micro-IoC injector intended for use in mobile (Xamarin /WP7.1+) environments. To simplify this usage the code is packaged as a single PCL for all environments.
The implementation is distinguished from other options by offering auto-wiring capabilities similar to a full IoC framework such as Ninjit, while weighing in at ~40 KB.
- Mono
- .Net 4.5
- Silverlight
- WP 7.1
- Auto-Wiring
- Configuration through code
- Configuration through attributes
- Generics Support
- Custom lifestyles
- Fast (top performer on IoC Container Shootout)
- Small
The quickest way to get started is via the Nuget Package (http://www.nuget.org/packages/IfInjector). For Xamarin developers there is a nuget extension available by going to Tools > Add-in Manage, then searching for 'nuget'.
Alternatively you may clone and compile the source code yourself on github: https://github.com/iamahern/IfInjector.git.
CMD> Install-Package IfInjector
IfInjector supports two ways to wire your components:
- Annotation based configuration
- Code based configuration You may use whichever method suits your development purposes.
// =================================
// Setup
// =================================
using IfInjector;
[ImplementedBy(typeof(MyType))]
interface IMyType { }
interface IMyOtherType{}
[Singleton]
class MyType : IMyType {
[Inject]
public MyType(IMyOtherType myOtherType) {
MyOtherType = myOtherType;
}
public IMyOtherType MyOtherType { get; private set; }
}
[Singleton]
class MyOtherType : IMyOtherType {}
// =================================
// Usage
// =================================
var injector = new Injector();
IMyType obj = injector.Resolve<IMyType>();
// =================================
// Setup
// =================================
using IfInjector;
interface IMyType { }
interface IMyOtherType{}
class MyType : IMyType {
// Constructor annotation is optional
// - it will use this constructor since it is the only one available
[Inject]
public MyType(IMyOtherType myOtherType) {
MyOtherType = myOtherType;
}
public IMyOtherType MyOtherType { get; private set; }
}
class MyOtherType : IMyOtherType {}
// =================================
// Usage
// =================================
var injector = new Injector();
injector.Register(Binding.For<IMyType>().To<MyOtherType>().AsSingleton());
injector.Register(Binding.For<IMyOtherType>().To<MyOtherType>().AsSingleton());
IMyType obj = injector.Resolve<IMyType>();
TODO