How Midway v1.0 Simplifies Node.js Development with IoC and Decorators

Midway v1.0, the core framework of the MidwayJs ecosystem, introduces IoC‑based dependency injection, web‑scenario decorators, full Egg.js plugin support, and a TypeScript‑first API, offering a concise example that shows how business code can stay clean and decoupled.

Node Underground
Node Underground
Node Underground
How Midway v1.0 Simplifies Node.js Development with IoC and Decorators

On this celebratory day, the Midway team is excited to announce the release of Midway v1.0, the core product of the MidwayJs ecosystem.

The repository remains at https://github.com/midwayjs/midway; stars are welcome.

IoC‑based decoupling of business code with unified dependency management and initialization.

Decorator shortcuts for common web scenarios to simplify development.

Full compatibility with Egg.js plugins, unified coding style via framework decorators.

TypeScript‑based, interface‑driven programming experience.

Dependency injection is introduced into complex business logic, allowing developers to focus on domain code without worrying about instance creation or initialization.

@provide()
@controller()
export class HomeController {
  @inject()
  reportService: IReportService;

  @get('/')
  async index(ctx) {
    ctx.body = await this.reportService.getReport();
  }
}

@provide()
class ReportService implements IReportService {
  @inject()
  reporter: IReportManager;

  async getReport(id: number) {
    return await this.reporter.get(id);
  }
}

In the example, HomeController depends on ReportService without any explicit instantiation, thanks to the "magic" of dependency injection.

Additional useful decorators such as @schedule, @init, and @plugin are also provided.

For more details, refer to the official documentation and the team's Zhihu column, links of which can be found in the "About Us" section of the public account.

Starring the repository is greatly appreciated and fuels continued development.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

TypeScriptIoCNode.jsdependency-injectiondecoratorsMidway
Node Underground
Written by

Node Underground

No language is immortal—Node.js isn’t either—but thoughtful reflection is priceless. This underground community for Node.js enthusiasts was started by Taobao’s Front‑End Team (FED) to share our original insights and viewpoints from working with Node.js. Follow us. BTW, we’re hiring.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.