inject_creator

Last updated:

0 purchases

inject_creator Image
inject_creator Images
Add to Cart

Description:

inject creator

inject_creator #

inject_creator is a convenient code generator for get_it.
Features #

Singleton
LazySingleton
Mutable
Alias
FactoryMethod
PostConstruct
DisposeMethod
Component

Getting started #
Install #
dependencies:
get_it: ^6.0.0
inject_creator: any

dev_dependencies:
build_runner: ^2.0.0
inject_creator_generator: any
copied to clipboard
Usage #
import 'main.dep.dart';

@EnableInjector(allReady: true)
// or @EnableInjector(entryPoint:'initDependencies', allReady: false)
void main() {
configDependencies();
// or initDependencies();
runApp(const MyApp());
}
copied to clipboard
example:
import 'main.dep.dart';

// sync
getXxxx();

// async
await getSharedPreferences();
copied to clipboard
generate code:
flutter pub run build_runner build
copied to clipboard
Example #
Singleton #
@Singleton()
class LoginService {}


@Singleton(tag: 'customNameService')
class CustomNameService {}

abstract class AbstractService {}

@Singleton(tag: 'default', as: AbstractService)
class AbstractServiceImpl extends AbstractService {}
copied to clipboard
LazySingleton #
@LazySingleton()
class LazySingletonService {}
copied to clipboard
Mutable #
@Mutable()
class NoSingletonService {}
copied to clipboard
PostConstruct #
@Singleton()
class LoginService {
@PostConstruct()
void init() {
print('PostConstruct init');
}
}
copied to clipboard
FactoryMethod #
@LazySingleton(tag: 'asyncService')
class AsyncService {
@FactoryMethod()
static Future<AsyncService> withDependencies(LoginService loginService) {
return Future.value(AsyncService());
}
}
copied to clipboard
DisposeMethod #
@LazySingleton()
class DbService {
@DisposeMethod()
void dispose() {}
}
copied to clipboard
Alias #
@LazySingleton()
class FactoryMethodService {
@FactoryMethod()
static Future<FactoryMethodService> withDependencies(
{@Alias('asyncService')
required Future<AsyncService> asyncService,
@Alias.by(SimpleAbstractService)
required AbstractService abstractService}) {
return Future(() => FactoryMethodService());
}
}
copied to clipboard
Third party #
@Component()
class VendorComponent {

@LazySingleton(tag: 'defaultSharedPreferences')
Future<SharedPreferences> get sharedPreferences =>
SharedPreferences.getInstance();

@DisposeMethod()
void dispose() {
sharedPreferences.then((value) => value.clear());
}
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.