Comments (2)
刚刚看了下源码,发现好像应该用 @Constant
这个注解
似乎要这样写
@Constant({ id: 'AAA', constantValue: new AAA("123") })
export default class {
}
但名字叫“常量”感觉是声明一个数值或字符串,而且定义在类上面感觉有些迷惑。
我觉得应该搞一个定义在函数上的 @Bean
的注解
class Factory {
@Bean
aaa() {
return new AAA("123")
}
}
这样明显就清晰多了,也和 Spring 里的一样
from malagu.
抱歉这么晚才回复。Malagu 框架提供了类似 @bean 的能力,如下所示:
import { autoBind } from '@malagu/core';
import './index';
export default autoBind(bind => {
bind('aaa').toDynamicValue(ctx => new AAA());
});
autoBind 方法一般用在一个模块的入口文件中。详细文档可以参阅:https://malagu.naily.cc/components/core/utils#autobind
from malagu.
Related Issues (20)
- 支持框架adonisjs
- Eventbus需求 HOT 1
- `getExternalModules` 优化
- [fc-plugin] trggier 返回的URL多展示几条 HOT 1
- 适配 Python 框架 HOT 1
- 添加 Prisma 示例
- support google cloud function
- copy package.json 增加pnpm字段
- 检查sample-app 项目使用 pnpm HOT 1
- adonis build 支持tsconfig
- 升级 oidc-provider
- [RFC] 支持pnpm monorepo HOT 3
- backend-app部署到Vercel 平台时找不到vercel.json HOT 2
- 优化对 Region 参数等参数校验,输出友好错误信息 HOT 1
- 建议增加对 Cloudflare 的 Workers 和 Pages 支持
- ts error when using malagu to deploy next.js 13
- 升级fc-plugin的runtime, 还有node版本 HOT 5
- First time use 'malagu serve' but with errors HOT 1
- [bug] 使用malagu init初始化backend-app 404 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from malagu.