Spring.NET &即时CMS
有没有什么方法可以使用 Spring.NET 将依赖项注入到 Immediacy CMS 控件中,理想情况下在初始化控件时无需使用 ContextRegistry ?
Is there any way to inject dependencies into an Immediacy CMS control using Spring.NET, ideally without having to use to ContextRegistry
when initialising the control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
作为一名前 Immediacy 员工,我经常看到此类问题。
将即时性视为位于框架之上的标准 .net Web 应用程序。
他们只是扩展了 Page 类等的基类,并添加了一些全局有用的对象。
Immediacy 确实有自己的控件基类等,但没有什么可以阻止您基于标准 .net 类创建自己的控件。
我见过的一个技巧是,您需要执行一些可能会破坏即时功能的特定操作,即创建一个子应用程序,然后在添加到主应用程序的自定义控件中从中调用页面。
这样,您的子应用程序就可以做它喜欢做的事情,而不会破坏任何内容,并且父即时应用程序只需从该应用程序读取流即可。
最简单的技巧是简单地创建一个只做一件事的控件...
最干净的其他方法是将所需的子组件实现为我所看到的 ashx 处理程序。
可能出现的唯一问题是,您失去了子应用程序中对象的即时框架,但您可以轻松地通过查询字符串传递一些关键信息,然后构建自己的“依赖项缓存”,其中包含您需要的内容。
我知道这不是一个理想的选择,但是当您需要做任何超出向页面或模板添加列表/类似插件的事情时,即时性确实会让生活变得困难。
As an ex Immediacy employee i used to see this sort of problem all the time.
Think of immediacy as being a standard .net web app that sits on top of the framework.
They have simply extended the base classes for things like the Page class and added some globally useful objects.
Immediacy does have its own base classes for controls ect but there's nothing stopping you creating your own controls based on the standard .net classes.
One trick I have seen where you need to do something specific that may break an immediacy function is to create a child application then call up pages from it within a custom control that you add to the main app.
This way your child app can do what it likes without breaking anything and the parent immediacy app and simply reads a stream from that app.
in its simplest form the trick is to simply create a control that does one thing ...
The cleanest other way to do this is to implement the required child component as an ashx handler from what i've seen.
The only issue that may bring up is that you lose the immediacy framework of objects in your child app, but you could easily pass in some key information via querystrings then build your own "depency cache" that contains the stuff you need.
It's not an ideal I know but immediacy does have a habit of making life difficult when you need to do anything above and beyond dropping in lists / similar plugins to pages or templates.
我将用我已经使用了一年多的 Immediacy 6.x 解决方案来回答这个问题。理论上,经过一些修改后,这应该可以与 Alterian CMC 7.x(Immediacy 的后继者)一起使用。
这里的问题是 Immediacy 已经在 web.config 中定义了一个处理所有 aspx 页面的处理程序。然而,我发现这可以用 web.config 中 Spring.NET 的
PageHandlerFactory
条目替换,就像大多数 Webforms 应用程序一样!然而,由于开箱即用,预览器仍然存在问题,因此仍然需要进行一些调整。让 Spring.NET 与即时控件完美配合的过程是:
将常用条目添加到 Spring.NET 的 web.config 如文档中所述。在本例中,我在 Spring.config 中获得了对象定义。
创建以下抽象基类来处理所有依赖注入工作:
SpringImmediacyControl.cs
这类似于服务器代码Spring.NET 文档的侧面控制。然而,额外的
OnInit
&需要 null 检查代码是因为预览器在 Immediacy 自己的预览器 HTTP 处理程序下呈现控件。这意味着需要手动调用 Spring.NET 的上下文注册表来注入依赖项。对于您希望与 Spring.NET 的控制反转容器一起使用的任何控件,请将相关条目添加到 Spring.config,例如:
SampleControl.cs
Spring.config
如果一切都正确完成,您将拥有写出“Hello world from Spring.NET!”的控件。在页面中使用时。
我使用过的所有代码都可以下载&
顺便说一句,如果您希望创建
ButtonPluginConfig
的 Spring.NET 兼容子类,则过程类似,只不过这些子类始终在下面执行Immediacy 自己的 HTTP Handler 用于控制配置,&因此始终需要调用 Spring.NET 的上下文注册表。我还在上面的要点中包含了一个从ButtonPluginConfig
派生的抽象类。I'm going to answer this one with a solution I've used for over a year with Immediacy 6.x. In theory, this should work with Alterian CMC 7.x (Immediacy's successor) with some modification.
The issue here is that Immediacy already has a handler defined in web.config that deals with all aspx pages. However, I've found this can be replaced with an entry for Spring.NET's
PageHandlerFactory
in web.config, as per most webforms apps!However, some tweaking is still needed since out of the box, there are still issues with the previewer. The process for getting Spring.NET to play nicely with an Immediacy Control is:
Add the usual entries to web.config for Spring.NET as outlined in the documentation. In this case I've got my object definitions in Spring.config.
Create the following abstract base class that will deal with all of the Dependency Injection work:
SpringImmediacyControl.cs
This is similar to the code for server side controls over on the Spring.NET documentation. However, the extra
OnInit
& null checking code is needed is because the previewer renders the control under Immediacy's own previewer HTTP Handler. This means a manual call to Spring.NET's context registry is needed to inject dependencies.For any control with which you wish to use with Spring.NET's Inversion of Control container, add the relelvant entry to Spring.config, for example:
SampleControl.cs
Spring.config
Provided everything's done correctly, you will have the control writing out "Hello world from Spring.NET!" when used in a page.
All of the code I've used can be downloaded & forked from here.
As an aside, the process is similar if you wish to create Spring.NET compatible subclasses of
ButtonPluginConfig
, except these subclasses are always executed under Immediacy's own HTTP Handler for control configuration, & so calling Spring.NET's context registry is always required. I've included an abstract class derived fromButtonPluginConfig
in the gist above as well.