Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

A Xamarin iOS library to enable dependency injection of UIViewControllers that use storyboards

License

Notifications You must be signed in to change notification settings

feature23/DependencySwizzler

Repository files navigation

iOS Dependency Swizzler

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.

Examples

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.

Custom

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

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)

License

This project is subject to the MIT license.

About

A Xamarin iOS library to enable dependency injection of UIViewControllers that use storyboards

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages