在 Coldbox 中使用wirebox如何从模型创建bean

发布于 2024-12-23 05:21:25 字数 317 浏览 4 评论 0原文

我还不擅长术语,所以请原谅/纠正我。另外我不知道如何使用 Coldspring 等,所以我尝试只使用wirebox。

我不想使用 beanFactory 插件,而只是直接从我的模型调用wirebox 方法。

目前我可以使用这个

<cfproperty name="bf" inject="coldbox:plugin:BeanFactory" scope="variables" />

How do it以便我可以调用wirebox的getInstance方法而不是beanFactory的getModel?

I am not good with the terminology yet, so please forgive/correct me. Also I have no idea hw to use Coldspring, etc, so I am trying to just use wirebox.

I want to not use the beanFactory plugin and just call wirebox methods straight from my model.

Currently I can use this

<cfproperty name="bf" inject="coldbox:plugin:BeanFactory" scope="variables" />

How do I do it so that I can call wirebox's getInstance method instead of beanFactory's getModel?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

笑忘罢 2024-12-30 05:21:25

在处理程序中,您可以使用属性注入让 Wirebox 注入 bean(与您发布的内容非常相似)。

基于标签

<cfproperty name='myModel' inject='id:MyModel' />

基于脚本

property name='myModel' inject='id:MyModel';

然后,您只需调用 myModel.someMethod() 即可在处理程序中的任何位置使用该模型。

还值得注意的是,如果您使用模型的 ID 进行注入,则不需要 inject 的值。 Wirebox 将尝试使用您指定的名称查找模型。你可以简化它。

基于标签

<cfproperty name='myModel' inject />

基于脚本

property name='myModel' inject;

Within the handler, you can have Wirebox inject beans using property injection (much like what you posted).

Tag Based

<cfproperty name='myModel' inject='id:MyModel' />

Script Based

property name='myModel' inject='id:MyModel';

You can then use the model anywhere in the handler by simply calling myModel.someMethod().

It's also worth noting that if you are injecting using the model's ID, then the value of inject isn't required. Wirebox will attempt to look up the model using the name you gave it. You could simplify it.

Tag Based

<cfproperty name='myModel' inject />

Script Based

property name='myModel' inject;
漆黑的白昼 2024-12-30 05:21:25

我不确定这是否是您正在寻找的答案,但是...

在处理程序中您可以执行此操作。

var oMyModel = populateModel("myModel");

在模型中你可以这样做。

var oMyModel = createobject("component", "myModel");

这能满足您的需求吗?

I am not sure this is the answer you are looking for but...

In the handler you can do this.

var oMyModel = populateModel("myModel");

In a model you can do this.

var oMyModel = createobject("component", "myModel");

Does this answer what you need?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文