Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dirk Seefeld 126 posts 665 karma points
    Nov 21, 2012 @ 10:52
    Dirk Seefeld
    0

    MVC v4.10.1 IoC with Unity

    Hi,

    I am just trying to use dependency injection with Unity base on this docu: https://github.com/umbraco/Umbraco4Docs/blob/master/Documentation/Reference/Mvc/using-ioc.md

    Within the SurfaceController class only the default constructor gets called so the dependency resolving never takes place. The YOD says: System.MissingMethodException: No parameterless constructor defined for this object.
    What is missing here?

    Btw: I have installed the Unity.Mvc3 package and try to register a simple test class with in Unity
    This does basically something like documented here http://www.codeproject.com/Articles/118881/Dependency-Injection-in-MVC-3-Was-Made-Easier
    and works fine in a plain VStudion MVC3 project.

    Yours,
    Dirk

  • Dirk Seefeld 126 posts 665 karma points
    Nov 22, 2012 @ 20:42
    Dirk Seefeld
    0

    I found a solution for my problem. The new way to hook into the application start seems to be implementing the IApplicationEventHandler like so:

    namespace MvcUmb410plus
    {
        public class MyApplication : Umbraco.Web.IApplicationEventHandler
        {
    
     #region IApplicationEventHandler Member
    
    
            public void OnApplicationStarted(UmbracoApplication httpApplication, Umbraco.Core.ApplicationContext applicationContext)
            {
                Bootstrapper.Initialise();
            }
    
            public void OnApplicationInitialized(UmbracoApplication httpApplication, Umbraco.Core.ApplicationContext applicationContext)
            {
            }
    
            public void OnApplicationStarting(UmbracoApplication httpApplication, Umbraco.Core.ApplicationContext applicationContext)
            {
            }
    
     #endregion
        }
    
        //public class MyApplication : Umbraco.Web.UmbracoApplication
        //{
        //  protected override void OnApplicationStarted(object sender, EventArgs e)
        //  {
        //    base.OnApplicationStarted(sender, e);
        //    Bootstrapper.Initialise();
        //  }
    
        //}
    }
  • Dirk Seefeld 126 posts 665 karma points
    Nov 26, 2012 @ 13:40
    Dirk Seefeld
    0

    Well, its just another example of missing something...

    The documentation does work. The only thing I have missed was to chnage the inherits clause / parameter in the global.asax like so:

    <%@ Application Codebehind="Global.asax.cs" Inherits="MyProject.MyApplication" Language="C#" %>
    
  • Edwin van Koppen 156 posts 270 karma points
    Jan 18, 2013 @ 11:23
    Edwin van Koppen
    0

    Did you have also the problem that the OnApplicationInitialized, OnApplicationStarting & OnApplicationStarted runs twice? If i put a debugger on the project i see two hits on the same code..

Please Sign in or register to post replies

Write your reply to:

Draft