MVC 2 / MVCContrib 中的包含处理

发布于 2024-08-25 02:31:11 字数 516 浏览 9 评论 0原文

我想通过组合和缩小 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 技术交流群。

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

发布评论

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

评论(3

む无字情书 2024-09-01 02:31:11

那么,MvcContrib.IncludeHandling 使用 MvcContrib 的 DependencyResolver 来查找必要的组件。它没有很好的记录(请参阅示例站点以获取更多详细信息,尽管在这种情况下使用自定义注入器)。

例如,MvcContrib.Castle 有一个用于该 IoC 容器的 WindsorDependencyResolver,您可以模仿它来使用 NInject(如果您 Google 一下可能会找到一些东西)。
初始化非常冗长,但是是这样的(容器是 Windsor 容器,在您的例子中,使用 NInject):

var httpContextProvider = new HttpContextProvider(HttpContext.Current);
var settings = IIncludeHandlingSettings)ConfigurationManager.GetSection("includeHandling");

container.Register(Component.For(typeof(IIncludeReader)).ImplementedBy(typeof(FileSystemIncludeReader)));            

container.Register(Component.For(typeof(IIncludeStorage)).ImplementedBy(typeof(StaticIncludeStorage)));           
container.Register(Component.For(typeof(IKeyGenerator)).ImplementedBy(typeof(KeyGenerator)));
container.Register(Component.For(typeof(IIncludeHandlingSettings)).Instance(settings));
container.Register(Component.For(typeof(IHttpContextProvider)).Instance(httpContextProvider));
container.Register(Component.For(typeof(IIncludeCombiner)).ImplementedBy(typeof(IncludeCombiner)));
container.Register(Component.For(typeof(IncludeController)).ImplementedBy(typeof(IncludeController)).LifeStyle.Transient);

DependencyResolver.InitializeWith(new WindsorDependencyResolver(Container));

这样您就可以注册所有需要的依赖项。请注意,您的 Web 配置中需要 includeHandler 部分。

<configSections>
    <section name="includeHandling" type="MvcContrib.IncludeHandling.Configuration.IncludeHandlingSectionHandler, MvcContrib.IncludeHandling"/>
</configSections>
<includeHandling>
</includeHandling>

我希望这有帮助。

Well, MvcContrib.IncludeHandling uses MvcContrib's DependencyResolver 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 a WindsorDependencyResolver 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):

var httpContextProvider = new HttpContextProvider(HttpContext.Current);
var settings = IIncludeHandlingSettings)ConfigurationManager.GetSection("includeHandling");

container.Register(Component.For(typeof(IIncludeReader)).ImplementedBy(typeof(FileSystemIncludeReader)));            

container.Register(Component.For(typeof(IIncludeStorage)).ImplementedBy(typeof(StaticIncludeStorage)));           
container.Register(Component.For(typeof(IKeyGenerator)).ImplementedBy(typeof(KeyGenerator)));
container.Register(Component.For(typeof(IIncludeHandlingSettings)).Instance(settings));
container.Register(Component.For(typeof(IHttpContextProvider)).Instance(httpContextProvider));
container.Register(Component.For(typeof(IIncludeCombiner)).ImplementedBy(typeof(IncludeCombiner)));
container.Register(Component.For(typeof(IncludeController)).ImplementedBy(typeof(IncludeController)).LifeStyle.Transient);

DependencyResolver.InitializeWith(new WindsorDependencyResolver(Container));

This way you can register all the dependencies that are needed. Beware that you need the includeHandler section in your web config.

<configSections>
    <section name="includeHandling" type="MvcContrib.IncludeHandling.Configuration.IncludeHandlingSectionHandler, MvcContrib.IncludeHandling"/>
</configSections>
<includeHandling>
</includeHandling>

I hope this helped.

萌梦深 2024-09-01 02:31:11

查看 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...

高速公鹿 2024-09-01 02:31:11

这是 DependencyResolver 设置的 Unity 版本。我将其作为 Unity 容器扩展来完成。

public class ConfigureMvcContrib : UnityContainerExtension
{
    protected override void Initialize()
    {
        var settings = (IIncludeHandlingSettings)ConfigurationManager.GetSection("includeHandling");

        Container
            .RegisterFactory<IHttpContextProvider>(c => new HttpContextProvider(HttpContext.Current))
            .RegisterFactory<IIncludeReader>(c => new FileSystemIncludeReader(c.Resolve<IHttpContextProvider>()))
            .RegisterType<IIncludeStorage, StaticIncludeStorage>()
            .RegisterType<IKeyGenerator, KeyGenerator>()
            .RegisterFactory<IIncludeCombiner, IncludeCombiner>()
            .RegisterInstance<IIncludeHandlingSettings>(settings);

        DependencyResolver.InitializeWith(new UnityDependencyResolver(Container));
    }
}

值得注意的是 IncludeHandling 设置对于 Web 集群设置来说并不理想,因为它的缓存方式。我必须推出自己的控制器操作,该操作需要合并和缩小文件列表。如果有人感兴趣,我可以提供更多信息。

Here is a Unity version of the DependencyResolver setup. I did it as a Unity container extension.

public class ConfigureMvcContrib : UnityContainerExtension
{
    protected override void Initialize()
    {
        var settings = (IIncludeHandlingSettings)ConfigurationManager.GetSection("includeHandling");

        Container
            .RegisterFactory<IHttpContextProvider>(c => new HttpContextProvider(HttpContext.Current))
            .RegisterFactory<IIncludeReader>(c => new FileSystemIncludeReader(c.Resolve<IHttpContextProvider>()))
            .RegisterType<IIncludeStorage, StaticIncludeStorage>()
            .RegisterType<IKeyGenerator, KeyGenerator>()
            .RegisterFactory<IIncludeCombiner, IncludeCombiner>()
            .RegisterInstance<IIncludeHandlingSettings>(settings);

        DependencyResolver.InitializeWith(new UnityDependencyResolver(Container));
    }
}

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.

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