Orchard模块加载事件

发布于 2024-12-22 01:11:14 字数 210 浏览 4 评论 0原文

我对 Orchard CMS 非常陌生,我已经开始编写我的第一个模块。我一直在寻找一种方法来检测我的模块何时从根网站初始化,但没有运气!

一位同事建议使用 WebActivator 和 PreApplicationStartMethod 属性来配置启动时调用的方法,但这不起作用。

有没有人设法做到这一点,果园是否提供像 IModule 这样的接口,可以让我挂钩模块初始化?

I'm very new to Orchard CMS and I have started writing my first module. I've been looking for a way to detect when my module has been initialized from the root website but have had no luck!

A colleague suggested using WebActivator and the PreApplicationStartMethod attribute to configure a method to be called on start up but this did not work.

Has anybody managed to accomplish this, is there an interface provided by orchard like IModule that will allow me to hook into module initialization?

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

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

发布评论

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

评论(3

夏夜暖风 2024-12-29 01:11:15

解决了!实现 Autofac.Module 并重写 Load(ContainerBuilder) 方法!

using Autofac;

public class MyModule : Module
{
    protected override void Load(ContainerBuilder builder)
    {
         // Module initialization here!
    }
}

Solved! Implement an Autofac.Module and override the Load(ContainerBuilder) method!

using Autofac;

public class MyModule : Module
{
    protected override void Load(ContainerBuilder builder)
    {
         // Module initialization here!
    }
}
我也只是我 2024-12-29 01:11:14

您可能会对两个事件处理程序感兴趣。 IFeatureEventHandlerIOchardShellEventsIFeatureEventHandler 接口为您提供模块启用、禁用、安装和卸载的挂钩。 IOrchardShellEvents 接口提供了用于激活和终止 Orchard Shell 的钩子。里面的东西应该能帮到你!

There are two event handlers that might interest you. IFeatureEventHandler and IOrchardShellEvents. The IFeatureEventHandler interface gives you hooks for modules enabling, disabling, installing, and uninstalling. The IOrchardShellEvents interface provides hooks for the activation and termination of the Orchard Shell. Something in there should do the trick for you!

戒ㄋ 2024-12-29 01:11:14

您不应该混淆 Autofac 和 Orchard 的模块。
要在 Orchard 模块启动时执行一些代码,您需要实现 IOrchardShellEvents 接口(Activated 方法)。另外不要忘记在 Autofac 中注册您的实现:

public class MyModule : Module
{
    protected override void Load(ContainerBuilder builder)
    {
        builder.RegisterType<Bootstrapper>().As<IOrchardShellEvents>().InstancePerLifetimeScope();
    }
}

You shouldn't mix up Autofac's and Orchard's modules.
To execute some code when Orchard's module starts you need to implement IOrchardShellEvents interface (Activated method). Also don't forget to register your implementation in Autofac:

public class MyModule : Module
{
    protected override void Load(ContainerBuilder builder)
    {
        builder.RegisterType<Bootstrapper>().As<IOrchardShellEvents>().InstancePerLifetimeScope();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文