All Projects → tomersh → Appleguice

tomersh / Appleguice

Licence: apache-2.0
Effortless dependency injection framework for Objective-C

Projects that are alternatives of or similar to Appleguice

Go Argmapper
A runtime dependency-injection library for Go that supports automatically chaining conversion functions to reach desired input and output types.
Stars: ✭ 101 (-22.9%)
Mutual labels:  dependency-injection
Xaml Code Experiences
A collection of the experiences I have collected during days of Xamarin and Wpf, while following the MVVM design pattern.
Stars: ✭ 114 (-12.98%)
Mutual labels:  dependency-injection
Cleanse
Lightweight Swift Dependency Injection Framework
Stars: ✭ 1,659 (+1166.41%)
Mutual labels:  dependency-injection
Swiftdi
SwiftDI the new way to use your dependency in Swift 5.1
Stars: ✭ 107 (-18.32%)
Mutual labels:  dependency-injection
Fierycrucible
A minimalist type safe Swift dependency injection library
Stars: ✭ 112 (-14.5%)
Mutual labels:  dependency-injection
Covid19 Notifier In
A sample Android App which notifies about COVID19 cases in 🇮🇳India after every 1 hour.
Stars: ✭ 116 (-11.45%)
Mutual labels:  dependency-injection
Momentum
MVC pattern for flutter. Works as state management, dependency injection and service locator.
Stars: ✭ 99 (-24.43%)
Mutual labels:  dependency-injection
Tsed
📐 Ts.ED is a Node.js and TypeScript framework on top of Express to write your application with TypeScript (or ES6). It provides a lot of decorators and guideline to make your code more readable and less error-prone.
Stars: ✭ 1,941 (+1381.68%)
Mutual labels:  dependency-injection
Contextserviceextension
🎃 [DEPRECATED] Allows to declare and use contexts services in scenario scoped container.
Stars: ✭ 113 (-13.74%)
Mutual labels:  dependency-injection
Awilix Koa
Awilix helpers/middleware for Koa 2
Stars: ✭ 121 (-7.63%)
Mutual labels:  dependency-injection
Rxgithub
An example of MVVM using RxSwift and Swinject (DI)
Stars: ✭ 109 (-16.79%)
Mutual labels:  dependency-injection
Wpplugin
Boilerplate for WordPress plugin using autoload, coding standard, webpack, PHP/JS tests, etc.
Stars: ✭ 112 (-14.5%)
Mutual labels:  dependency-injection
Dinoloop
Rest API framework built on top of expressjs powered by Typescript.
Stars: ✭ 115 (-12.21%)
Mutual labels:  dependency-injection
Dagger2 Mvp Sample
Android Sample to explain Dagger 2 and MVP in android applications.
Stars: ✭ 106 (-19.08%)
Mutual labels:  dependency-injection
Deli
Deli is an easy-to-use Dependency Injection(DI).
Stars: ✭ 125 (-4.58%)
Mutual labels:  dependency-injection
No Framework Tutorial
A small tutorial to show how to create a PHP application without a framework.
Stars: ✭ 1,357 (+935.88%)
Mutual labels:  dependency-injection
Servicecontainerextension
📻 Allows to declare own services inside Behat container without writing an extension.
Stars: ✭ 114 (-12.98%)
Mutual labels:  dependency-injection
Kotlin Mvvm Architecture
Android Architecture Design Patterns using Kotlin, MVVM, Dagger2, LiveData, Room, MediatorLiveData, NetworkBoundResources, Retrofit, AndroidX, ViewModels, Dependency Injection using Dagger2, Repository pattern.
Stars: ✭ 126 (-3.82%)
Mutual labels:  dependency-injection
Scrutor
Assembly scanning and decoration extensions for Microsoft.Extensions.DependencyInjection
Stars: ✭ 1,915 (+1361.83%)
Mutual labels:  dependency-injection
Harrypotter
🧙🏻 Sample HarryPotter application based on MVVM architecture (ViewModel, LiveData, Repository, Coroutines, Koin or Dagger-Hilt)
Stars: ✭ 116 (-11.45%)
Mutual labels:  dependency-injection

AppleGuice

Effortless dependency injection framework for Objective-C

Build Status Coverage Status CocoaPoads

Who is using it?

Flashcards+ FlashCards+ CheggApp Chegg – Textbooks, eTextbooks & Study Tools

Are you using AppleGuice and your app is not on the list? Drop me a line.

What AppleGuice does for you?

AppleGuice helps you write clean, reuseable and testable code by allowing you to easily inject your services to any class. Other dependency injection frameworks require binding, xml editing or initializing your classes with a special method. With AppleGuice all you have to do is declare the injected type and thats it. As a bonus, you will still be able to initialize classes with [[MyClass alloc] init] so it is even easier to integrate it with your existing code base.

Show Me

Inject your first injectable instance with 3 simple steps:

Start AppleGuice


//AppDelegate.m

#import <AppleGuice/AppleGuice.h>

+(void) initialize {
    [AppleGuice startService];
}

Create your injectable service

Mark your injectable service with the protocol AppleGuiceInjectable so AppleGuice will find it.


@protocol MyServiceProtocol <AppleGuiceInjectable>

-(void) doStuff;

@end

@interface MyService : NSObject<MyServiceProtocol>
@end

@implementation MyService
...
@end

Enjoy automatic injection while coding

Create an ivar prefixed with the ioc prefix (the default is _ioc_). AppleGuice will automatically inject the proper implementation when calling the init method.

//MyClass.h
@interface MyClass : NSObject

@property (nonatomic, strong) id<MyServiceProtocol> ioc_myService;

@end

//MyClass.m
@implementation MyClass

//Now, you can use _ioc_myService anywhere. Even in the init function!

-(id) init {
  self = [super init];
  [self.ioc_myService doStuff];
  return self;
}
@end

AppleGuice initialized _ioc_myService without any manual binding!

Stub with ease while testing

#import <AppleGuice/AppleGuice.h>

@implementation MyClassTests {
    MyClass* classUnderTest;
}

-(void)setUp
{
    [super setUp];
    [AppleGuice startService];
    [AppleGuice setInstanceCreationPolicy:AppleGuiceInstanceCreationPolicyCreateMocks];
    classUnderTest = [[MyClass alloc] init];
}

-(void) test_foo_returnsValue {
  //the injectable ivar is initialized with a mock. You can stub methods on it as you normally do with OCMock.
  [[[classUnderTest.ioc_myService expect] andReturn:@"someString"] doStuff:OCMOCK_ANY];
  
  [classUnderTest foo];
  
  [classUnderTest.ioc_myService verify];
}

*When testing, AppleGuice works best with OCMock.

Inject In every flavour

Injecting a service is done by declering an ivar in a class. You can add it in the interface, implementation, as a property or even inside a private category. AppleGuice will find it. Injection comes in three flavours:

@interface MyClass () {
    MyService* _ioc_MyService; //will create an instance of MyService.
    id<MyServiceProtocol> _ioc_MyService //will create an instance of the first class conforming to MyServiceProtocol.
    NSArray* _ioc_MyProtocol //will return an array containing instances of all classes conforming to MyProtocol
}

More features

Singletons in a snap

Instead of messing your code with shared instance declerations or macros, you can just add AppleGuiceSingleton to the implemented protocols list and AppleGuice will always return the same instance.

@protocol MyServiceProtocol <AppleGuiceInjectable, AppleGuiceSingleton>
@end

Circular dependency support

AppleGuice can handle circular depenency between injected classes as long as the dependent classes conforms to AppleGuiceSingleton.

LazyLoad objects

You can configure AppleGuice to inject a proxy object instead of the real service. Once the service is needed (A method in the service is called) the proxy will be replaced with the real object.

//add in your AppDelegate
[AppleGuice setInstanceCreationPolicy:AppleGuiceInstanceCreationPolicyLazyLoad];

Ready to start?

Check out the quick installation guide.

Documentation can be found here. githalytics.com alpha

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].