A Xamarin.iOS library that uses "method swizzling" from the Objective-C runtime to allow property-setter dependency injection of UIViewControllers instantiated by storyboards. If you're unfamiliar with the concept of method swizzling see Mattt Thompson's excellent post at NSHipster. For a deeper dive, see Apple's documentation for the Objective-C runtime reference.
var container = new UnityContainer();
/* Initialize container */
var buildUpStrategy = new UnityBuildUpStrategy(container);
StoryboardInjector.SetUp(buildUpStrategy);
Note: Under the hood, the UnityBuildUpStrategy
adds a Unity extension to enable property setter injection of all publicly settable properties of a type registered with the container.
var container = new TinyIoCContainer();
/* Initialize container */
var buildUpStrategy = new TinyIoCBuildUpStrategy(container);
StoryboardInjector.SetUp(buildUpStrategy);
Note: Because TinyIoC is not installable as a DLL via NuGet (it is installed as a single C# source file), TinyIoC is included with the DependencySwizzler.TinyIoC NuGet package. If you want to install this package via NuGet, you cannot do so with TinyIoC already installed in your project.
var buildUpStrategy = new CustomBuildUpStrategy(viewController => {
/* custom logic to build up dependencies */
});
StoryboardInjector.SetUp(buildUpStrategy);
You may also pass a delegate directly to the SetUp()
method.
StoryboardInjector.SetUp(viewController => {
/* custom logic to build up dependencies */
});
Installation is simplest via NuGet. There are separate packages for the core library and each container implementation. You may also compile the source directly in your project.
Install-Package DependencySwizzler
(NuGet Page)Install-Package DependencySwizzler.Unity
(Nuget Page)Install-Package DependencySwizzler.TinyIoC
(Nuget Page)
This project is subject to the MIT license.