Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8518775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:04:39+00:00 2026-06-11T06:04:39+00:00

I have a custom ViewEngine that I am using with my MVC4 web app.

  • 0

I have a custom ViewEngine that I am using with my MVC4 web app.

I register is currently in the Global.asax like this:

ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new CustomViewEngine());

In my CustomViewEngine class I have properties of classes that are available through my IOC implementation (using CastleWindsor)

At the moment I could access the windsor resolver directly in the CustomViewEngine and resolve them, but what I would really like to do is have the ViewEngine resolved by windsor and get all those bits for free. Without having to do it explicitly.

Is this even possible? I would want the ViewEngine then to be resolved per WebRequest.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:04:41+00:00Added an answer on June 11, 2026 at 6:04 am

    How about something like this?

        public class DependencyViewEngine : RazorViewEngine
        {
            public override ViewEngineResult FindPartialView(ControllerContext controllerContext, string partialViewName, bool useCache)
            {
                var result = base.FindPartialView(controllerContext, partialViewName, useCache);
                result.ViewEngine = // resolve view engine
                return result;
            }
    
            public override ViewEngineResult FindView(ControllerContext controllerContext, string viewName, string masterName, bool useCache)
            {
                var result = base.FindView(controllerContext, viewName, masterName, useCache);
                result.ViewEngine = // resolve view engine
                return result;
            }
    
        }
    

    Then

        ViewEngines.Engines.Clear();
        ViewEngines.Engines.Add(new DependencyViewEngine());
    

    EDIT:

    How about implementing the dependency resolver to use your container?

    public class CustomDependencyResolver : IDependencyResolver
    {
        public CustomDependencyResolver(IContainer container)
        {
           // ...
        }
    
        public object GetService(Type serviceType)
        {
            // pass resolution off to your container
        }
        public IEnumerable<object> GetServices(Type serviceType)
        {
            // pass resolution off to your container
        }
    }
    

    Then

    protected void Application_Start()
    {
       ViewEngines.Engines.Clear();
       var resolver = new CustomDependencyResolver(container);
       DependencyResolver.SetResolver(resolver);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom classes that I currently instantiate within App.xaml as resources. I want
currently I have a custom VirtualPathProvider in a Asp.net MVC web application. This VirtualPathProvider
I have custom assembly that is loaded on runtime. at this point i have
I have custom button, with an image that I'd like to shift down within
We have custom cms that currently sits on a vendor's subdomain, such as cms.vendor.com.
I have custom UITableViewCell . It contains UITextLabel . When I press this cell
I have custom validation rule: public function customRule($check) { } Inside this rule I
We have custom headers in the Silverlight DataGrid using the ContentTemplate. We've got a
I have custom event that has several different subscribers who will all use the
I have custom gallery. Gallery represents items that are frame layout. There are one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.