Code Monkey home page Code Monkey logo

Comments (2)

mlkt avatar mlkt commented on July 22, 2024

刚刚看了下源码,发现好像应该用 @Constant 这个注解

似乎要这样写

@Constant({ id: 'AAA', constantValue: new AAA("123") })
export default class {
}

但名字叫“常量”感觉是声明一个数值或字符串,而且定义在类上面感觉有些迷惑。

我觉得应该搞一个定义在函数上的 @Bean 的注解

class Factory {
   @Bean
   aaa() {
     return new AAA("123")
   }
}

这样明显就清晰多了,也和 Spring 里的一样

from malagu.

muxiangqiu avatar muxiangqiu commented on July 22, 2024

抱歉这么晚才回复。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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.