MVC 2 / MVCContrib 中的包含处理
我想通过组合和缩小 javascript 和 CSS
文件来改进我的页面。由于 MVCContrib 已经包含一个名为 IncludeHandling
的项目,我查看了不幸留下的项目我有一些未解答的问题:
该过程涉及相当多的接口和对象。现在我正在使用 Ninject.Mvc
,但似乎 MvcContrib.IncludeHandling
正在使用一些额外的(自制的?)DI?我可以解决这个问题吗?有谁用过这个并且可以分享一些经验吗?
其次,经常听到的建议是将静态内容放在不同的域中,这样请求就不会包含cookie等,使服务器更容易处理请求。但是我如何将其与自动包含处理结合起来 - 这不一定在同一个应用程序中提供服务?
编辑:我发现整个事情中实际上只有一个解析调用,我真的很想知道为什么他们使用 DI 来实现这一点...考虑那里的分叉...
I'd like to improve my page by combining and minifying javascript and CSS
files. Since MVCContrib already contains a project called IncludeHandling
, I took a look at that which unfortunately left me with unanswered questions:
There is quite a set of interfaces and objects involved in the process. Now I'm using Ninject.Mvc
, but it seems that MvcContrib.IncludeHandling
is using some additional (home-brewed?) DI? Can I work around this? Has anybody used this and can share some experiences?
Secondly, advice that is often heard is to put static content on different domains so the request does not contain cookies and the like, making it much easier for the server to handle the request. But how can I combine this with automatic inclusion handling - isn't that necessarily served in the same application?
EDIT: Figured that there is really just a single resolve call in the whole thing, i really wonder why they use DI for that... Thinking about a fork there...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
那么,
MvcContrib.IncludeHandling
使用 MvcContrib 的DependencyResolver
来查找必要的组件。它没有很好的记录(请参阅示例站点以获取更多详细信息,尽管在这种情况下使用自定义注入器)。例如,
MvcContrib.Castle
有一个用于该 IoC 容器的WindsorDependencyResolver
,您可以模仿它来使用 NInject(如果您 Google 一下可能会找到一些东西)。初始化非常冗长,但是是这样的(容器是 Windsor 容器,在您的例子中,使用 NInject):
这样您就可以注册所有需要的依赖项。请注意,您的 Web 配置中需要 includeHandler 部分。
我希望这有帮助。
Well,
MvcContrib.IncludeHandling
uses MvcContrib'sDependencyResolver
to find the necessary components. It's not very well documented (see the sample site for more detail, although in that case uses a custom injector).For example,
MvcContrib.Castle
has aWindsorDependencyResolver
for that IoC container that you can mimic to use NInject (there may be something if you Google around).The initialization is quite verbose, but goes like this (container is the Windsor container, in your case, use NInject):
This way you can register all the dependencies that are needed. Beware that you need the includeHandler section in your web config.
I hope this helped.
查看 Asp.Net Ajax Minifier。 http://www.asp.net/ajaxlibrary/ajaxminquickstart.ashx
您可以设置 MS Build 任务,在构建时它将在项目中查找并缩小 Css 和 Js 文件...
Check out the Asp.Net Ajax Minifier. http://www.asp.net/ajaxlibrary/ajaxminquickstart.ashx
It ships with a MS Build task that you can setup where on build it will find and minify Css and Js files in your project...
这是 DependencyResolver 设置的 Unity 版本。我将其作为 Unity 容器扩展来完成。
值得注意的是 IncludeHandling 设置对于 Web 集群设置来说并不理想,因为它的缓存方式。我必须推出自己的控制器操作,该操作需要合并和缩小文件列表。如果有人感兴趣,我可以提供更多信息。
Here is a Unity version of the DependencyResolver setup. I did it as a Unity container extension.
It is worth noting that the IncludeHandling setup is not ideal for a web cluster setup as is because of the way it does caching. I had to roll my own controller action that took a list of files to combine and minify. I can provide more info if anyone is interested.