modular_core 1.1.4
modular_core: ^1.1.4 copied to clipboard

Smart project structure with dependency injection and route management

modular_core #

Injector and Tracker.

Use Module for Route or Bind(DI) or both. #


class OnlyRouteModule extends RouteContextImpl {
  @override
  List<ModularRoute> get routes => [
        CustomRoute(name: '/'),
      ];
}

class OnlyBindModule extends Module {
    List<Bind> get binds => [
      Bind.singleton((i) => GlobalController(), export: true),
  ];
}


class MyModule extends RouteContextImpl {

  List<Module> get imports => [OnlyBindModule()];


  List<Bind> get binds => [
      Bind.singleton((i) => MyController(i<GlobalController>())),
  ];

  @override
  List<ModularRoute> get routes => [
        CustomRoute(name: '/'),
        CustomRoute(name: '/product/:id'),
        CustomRoute(name: '/product/test'),
        CustomRoute.module('/only', module: OnlyRouteModule()),
      ];
}


Execute: #


main(){
    // start module
    ModularTracker.runApp(MyModule());

    //get routes
    final route = ModularTracker.findRoute('/');
    final routeForOnlyRoute = ModularTracker.findRoute('/only/');
    final route = ModularTracker.findRoute('/product/1', data: MyArgs());

    //get binds
    final controller = ModularTracker.injector.get<MyController>();

    //finishApp
    ModularTracker.finishApp();
}

Auxiliary classes #

  • CustomRoute - ModularRoute Implementation.
  • ModularRoute - abstract for create route.
  • Middleware - abstract.
3
likes
110
pub points
94%
popularity

Publisher

flutterando.com.br

Smart project structure with dependency injection and route management

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

characters, meta, modular_interfaces

More

Packages that depend on modular_core