singleton_manager_generator 2.2.2 copy "singleton_manager_generator: ^2.2.2" to clipboard
singleton_manager_generator: ^2.2.2 copied to clipboard

CLI tool that generates dependencyInjectionFactory() constructors for @dependencyInjectable classes.

Changelog #

2.2.2 - 2026-08-02 #

Fixed #

  • A super.field constructor parameter (Dart's super-parameter shorthand) was silently dropped instead of being resolved, because it carries no explicit type of its own. The generated factory ended up calling the constructor with that argument missing entirely, producing code that doesn't even compile whenever the parameter is required. The parser now resolves the parameter's type from the superclass's own default constructor (declared in the same file or a different one), including through further super./field-formal chains.

2.2.1 - 2026-08-02 #

Fixed #

  • --registry-output no longer omits the import for an interface declared in a different file than the class implementing it. Previously the generated registry file only imported each connected class's own file — if IFoo lived in interfaces.dart and FooImpl implements IFoo lived in foo_impl.dart, the generated connectInstance<IFoo, FooImpl>(...) call referenced an undefined IFoo and failed to compile. The generator now scans every input file (not just @dependencyInjectable-annotated ones) to find where each connected interface is declared, and adds that file's import too when it differs from the class's own.

2.2.0 - 2026-08-02 #

Added #

  • dependencyInjectionFactory() now always takes an optional {String key = 'default', String subkey = 'default'} — every generated factory can be told which subkey it is itself being resolved under
  • The generator reads @Subkey.inherited() on a constructor parameter and emits subkey: subkey (forwarding the factory's own subkey argument) instead of a literal string, so nested dependencies can transitively resolve under the same subkey as the instance being built
  • --registry-output now forwards a class's own @DependencyInjectable(subkey: '...') into its generated factory call (ClassName.dependencyInjectionFactory(key: key, subkey: '...')), so any @Subkey.inherited() parameter of an auto-registered class sees its class-level subkey too

2.1.1 - 2026-08-02 #

Documentation #

  • Updated the README's generated-factory example, parameter-mapping table, and CLI walkthrough to show the {String key = 'default'} parameter and @Subkey('...') support
  • Replaced the stale registerAllSingletons() example under "Generating a registry file" with the current MainInjection<ProjectName>Mixin / MainInjection<ProjectName> output, including the auto-detected <ProjectName> and an example of overriding the before-hook to hand-wire a non-@dependencyInjectable dependency

2.1.0 - 2026-08-02 #

Added #

  • dependencyInjectionFactory() now takes an optional {String key = 'default'} parameter, threaded through every generated getInstance/getInstanceNullable call
  • The generator reads @Subkey('...') on constructor parameters and emits subkey: '...' in the corresponding getInstance/getInstanceNullable call, disambiguating parameters that share an interface type
  • The generator reads the class-level @DependencyInjectable(subkey: '...') annotation and connects that class under the given subkey in --registry-output
  • --registry-output now auto-detects <ProjectName> (PascalCase) from the nearest pubspec.yaml's name: field, walking up from --input

Changed #

  • Breaking: --registry-output no longer emits a bare registerAllSingletons() top-level function. It now emits a MainInjection<ProjectName>Mixin mixin — with overridable beforeRegisterAllSingletons<ProjectName> / registerAllSingletons<ProjectName> / afterRegisterAllSingletons<ProjectName> methods — plus a concrete MainInjection<ProjectName> class built on top of it (class MainInjection<ProjectName> with MainInjection<ProjectName>Mixin). Calling registerAllSingletons<ProjectName>({String key = 'default'}) on an instance now connects everything (calling the before/after hooks around it); each call is independent per key, so multiple singleton graphs can be set up side by side.
  • Breaking: RegistryFileGenerator.generate now requires a projectName argument; RegistryEntry gained an optional subkey field.

2.0.0 - 2026-08-01 #

Added #

  • New --registry-output (-r) CLI flag: writes a .dart file that connects every discovered @dependencyInjectable class to RegistryManager.instance, each to its generated dependencyInjectionFactory(), via a single registerAllSingletons() function
  • The type each class is registered under is inferred from the first interface in its implements clause; classes implementing nothing are registered under their own type
  • Import paths in the generated registry file are computed relative to the registry file's own location, so --registry-output can point anywhere, independent of --input / --output
  • DIClassInfo now also captures interfaceName (nullable) alongside the existing constructor/parameter info
  • New RegistryEntry model and RegistryFileGenerator in lib/src/

Changed #

  • Breaking: complete rewrite around the new singleton_manager API. The old @isSingleton / @isInjected / @isMandatoryParameter / @isOptionalParameter annotations, the ISingletonStandardDI contract, and the separate <Class>DI subclass output are all gone.
  • The generator now scans for classes annotated with @dependencyInjectable and writes a factory <ClassName>.dependencyInjectionFactory() directly into the annotated class itself, as its last member, right before the closing } — no more _di.dart companion file.
  • The factory is built from the class's default (unnamed) constructor: each parameter is resolved via RegistryManager.instance.getInstance<T>() (non-nullable types) or RegistryManager.instance.getInstanceNullable<T>() (nullable types), then forwarded to the constructor positionally or by name, matching the parameter's original shape (positional-required, positional-optional, or named/required-named).
  • Field-formal constructor parameters (this._field) with no explicit type in the constructor signature now have their type resolved from the matching field declaration.
  • Running the generator again on an already-rewritten file replaces the existing factory in place instead of duplicating it (idempotent re-runs).
  • The singleton_manager import is automatically inserted if missing from the source file.
  • --input / --output / --verbose / --help CLI flags are unchanged; --output defaults to --input, so by default the generator rewrites the real source files in place.

Removed #

  • SingletonClassInfo, InjectedFieldInfo, ConstructorParameterInfo models and the AugmentationGenerator — replaced by DIClassInfo, DIParam, and DIFactoryGenerator / FileRewriter.

1.4.2 - 2026-04-30 #

Fixed #

  • @isOptionalParameter on nullable fields no longer includes the ? suffix in SingletonDIAccess.exists<T>() and SingletonDIAccess.get<T>() generic type arguments, since the DI container stores non-nullable types

1.4.1 - 2026-04-30 #

Fixed #

  • Generated initializeWithParametersDI() factory now uses ClassNameDI() instead of ClassNameDI.emptyForDI() when no constructor parameters are present, making it consistent with the initializeDI() factory (follow-up to v1.4.0)

1.4.0 - 2026-03-27 #

Changed #

  • Breaking: generated DI subclass now uses the default constructor instead of .emptyForDI(), while the parent class emptyForDI() contract is preserved via super.emptyForDI()
    • ClassNameDI.emptyForDI() : super.emptyForDI()ClassNameDI() : super.emptyForDI()
    • initializeDI() factory instantiates via ClassNameDI() instead of ClassNameDI.emptyForDI()
    • The parent class must still define ClassName.emptyForDI() — only the DI subclass naming changes

1.3.1 - 2026-03-26 #

Fixed #

  • Parser now correctly preserves generic type arguments in field types (e.g. IErmesBookRepository<BookData> was stripped to IErmesBookRepository)
    • _extractFieldType is now recursive and captures NamedType.typeArguments
    • Supports single generics (IRepository<BookData>), multi-parameter generics (IMap<String, BookData>), nested generics (ICache<Map<String, int>>), and nullable generics (IRepository<BookData>?)
    • Generated SingletonDIAccess.get<T>() calls now include the full generic type, e.g. get<IErmesBookRepository<BookData>>()

Added #

  • Tests for generic type support: parser tests, generator tests, and integration tests (including artifact files in lib/test_artifacts/integration_tests/lib/src/params/)

1.3.0 - 2026-03-26 #

Changed #

  • Breaking: generated DI class no longer uses the default constructor — renamed to .emptyForDI() to avoid conflicts when the parent class also defines a default constructor
    • ClassNameDI() : super()ClassNameDI.emptyForDI() : super()
    • initializeDI() factory instantiates via ClassNameDI.emptyForDI()
    • initializeWithParametersDI() factory instantiates via ClassNameDI.emptyForDI() when no constructor parameters are present, or via ClassNameDI(params) when constructor parameters exist

1.2.0 - 2026-03-25 #

Added #

  • @isOptionalParameter annotation now supported on fields (in addition to constructor parameters)
    • Parser sets a new isOptional flag on InjectedFieldInfo when @isOptionalParameter is found on a field
    • In initializeDI(): optional fields are guarded with if (SingletonDIAccess.exists<T>()) before injection
    • In initializeWithParametersDI(): optional fields appear as nullable named parameters {T? fieldName}; assigned directly if provided

Changed #

  • initializeDI() now injects all annotated fields including @isMandatoryParameter fields (previously excluded). This makes initializeDI() a full singleton factory where every dependency is resolved from the container
  • initializeWithParametersDI() no longer calls initializeDI() internally. Instead it injects each category of field explicitly:
    • @isInjected fields → always fetched from container via SingletonDIAccess.get<T>()
    • @isOptionalParameter fields → assigned from the optional named parameter
    • @isMandatoryParameter fields → assigned from the required positional parameter

1.1.3 - 2026-03-25 #

Changed #

  • Parser now emits a warning when a field annotated with @isOptionalParameter has a non-nullable type (e.g., String instead of String?)

1.1.0 - 2026-03-24 #

Added #

  • Support for @isMandatoryParameter and @isOptionalParameter annotations on constructor parameters
  • New ConstructorParameterInfo model to represent annotated constructor parameters
  • Parser now extracts constructor parameters annotated with @isMandatoryParameter / @isOptionalParameter
  • Generator creates a typed DI constructor that mirrors the original constructor signature
  • New initializeWithParametersDI() factory generated for classes with annotated constructor parameters
    • Mandatory parameters become positional arguments in the factory
    • Optional parameters become named optional arguments in the factory
  • No-arg initializeDI() factory is omitted when mandatory constructor parameters are present (avoids compile error)
  • initializeWithParametersDI() and @isInjected field injection can be combined in the same class

1.0.5 - 2026-03-24 #

Changed #

  • Generated files now include // ignore_for_file: directives_ordering, library_prefixes, unnecessary_import, unused_import, lines_longer_than_80_chars, cascade_invocations to suppress analyzer warnings in generated code

1.0.4 - 2026-03-18 #

Changed #

  • Generated factory initializeDI() now instantiates ClassNameDI() directly instead of casting ClassName() as ClassNameDI
  • Generated DI class now includes an explicit default constructor ClassNameDI() : super() to ensure correct subclass instantiation

1.0.3 - 2026-03-17 #

Changed #

  • unused_import is now treated as an error (moved to analyzer.errors in analysis_options.yaml)

1.0.2 - 2026-03-16 #

Fixed #

  • Combined instance creation and cast into a single statement in the generated initializeDI() factory — as ClassDI is now on the same line as the constructor call

1.0.1 - 2026-03-16 #

Fixed #

  • Generated DI files now use the correct relative import path for the source class when the output directory differs from the source directory (e.g. import 'impl/socket/my_service.dart' instead of import 'my_service.dart')
  • Generated DI files now include all imports from the source file, rebased relative to the output file's location — field types referenced by @isInjected (e.g. interface types) are therefore always resolvable

1.0.0 - 2026-03-16 #

First stable release - The singleton_manager_generator API is now stable and ready for production use.

Changed #

  • Removed dependency on singleton_manager_annotations (now part of singleton_manager)
  • Annotations are now referenced from singleton_manager package

Fixed #

  • CRITICAL: Fixed undefined getter 'name2' in source_parser.dart that caused generator to crash
    • Changed typeAnnotation.name2.lexeme to typeAnnotation.name.lexeme
    • Generator now correctly extracts field type names from class declarations
  • Fixed unused imports in test files
  • Resolved all dart analyze issues (cascade invocations, deprecated member usage)

Improved #

  • Simplified dependency chain by removing intermediate annotation package
  • Code quality: Optimized cascade operators in test suite
  • All tests pass with zero analyzer errors or warnings

0.1.4 - 2026-03-16 #

Fixed #

  • CRITICAL: Fixed undefined getter 'name2' in source_parser.dart that caused generator to crash
    • Changed typeAnnotation.name2.lexeme to typeAnnotation.name.lexeme
    • Generator now correctly extracts field type names from class declarations
  • Fixed unused imports in test files
  • Added singleton_manager as dev dependency for integration tests
  • Resolved all dart analyze issues (cascade invocations, deprecated member usage)
  • Added ignore comments for analyzer deprecation warnings that are not yet available in analyzer ^10.0.0

Improved #

  • Code quality: Optimized cascade operators in test suite
  • All tests pass with zero analyzer errors or warnings

0.1.3 - 2026-03-16 #

Fixed #

  • Removed workspace resolution (published packages shouldn't have workspace resolution)
  • Analyzer ^10.0.0 is the latest version compatible with test package

0.1.2 - 2026-03-16 #

Fixed #

  • Updated analyzer dependency to ^10.0.0 (latest compatible version with build package)

0.1.1 - 2026-03-16 #

Fixed #

  • Updated analyzer dependency to ^8.0.0 for compatibility with test package

0.1.0 - 2026-03-16 #

Added #

  • Initial release of singleton_manager_generator
  • CLI tool for generating Dart augmentation files for @isSingleton classes
  • Automatic code generation for ISingletonStandardDI implementations
  • Support for @isInjected field annotations
  • Verbose logging support
  • Comprehensive test suite
  • Integration tests for CLI functionality

Features #

  • Scans Dart source files for @isSingleton and @isInjected annotations
  • Generates augmentation files with ISingletonStandardDI implementations
  • Creates initializeDI() factory methods for each singleton class
  • Supports multiple injected fields per class
  • Minimal overhead using Dart's analyzer package for lightweight AST parsing
  • CLI options: --input, --output, --verbose, --help
0
likes
0
points
573
downloads

Publisher

unverified uploader

Weekly Downloads

CLI tool that generates dependencyInjectionFactory() constructors for @dependencyInjectable classes.

Repository (GitHub)
View/report issues

Topics

#singleton #dependency-injection #code-generation #annotations

License

unknown (license)

Dependencies

analyzer, args, path

More

Packages that depend on singleton_manager_generator