Copied to clipboard

Flag this post as spam?

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


  • Siavash Mortazavi 24 posts 145 karma points
    Sep 15, 2016 @ 18:50
    Siavash Mortazavi
    0

    Umbraco Vault conflict with Simple Injector IoC

    I have this piece of code to set up Umbraco Vault and initialize my Simple Injector IoC container:

    public class AxioApplicationStartup : ApplicationEventHandler
        {
            protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {            
                Vault.RegisterViewModelNamespace("Axiometrics.Web.ViewModels", "Axiometrics.Web");
                DefaultRenderMvcControllerResolver.Current.SetDefaultControllerType(typeof(VaultRenderMvcController));
            }
    
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                base.ApplicationStarted(umbracoApplication, applicationContext);
    
                SimpleInjector.Container container = new SimpleInjector.Container();
                container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
                //container.Register<ILogger, FileLogger>();
                container.RegisterMvcControllers(Assembly.GetExecutingAssembly());
                container.RegisterMvcIntegratedFilterProvider();
                container.Verify();
                DependencyResolver.SetResolver(
                new SimpleInjectorDependencyResolver(container));
            }
        }
    

    If I run it as is, I receive this error: "An MVC filter provider has already been registered for a different Container instance. Registering MVC filter providers for different containers is not supported by this method." which is happening on this line: container.RegisterMvcIntegratedFilterProvider();

    If I comment out this line of code that has container.RegisterMvcIntegratedFilterProvider(); and rerun, then I receive this error: "No registration for type VaultRenderMvcController could be found and an implicit registration could not be made. Please note that the container instance you are resolving from contains no registrations. Could it be that you accidentally created a new -and empty- container? For the container to be able to create VaultRenderMvcController it should have only one public constructor: it has 2. See https://simpleinjector.org/one-constructor for more information."

    I have no idea how to solve this problem, but my guess is either Umbraco or the Vault component is using another IoC container internally that is causing conflicts with my Simple Injector initialization.

    Could you please help me solve this problem? Thanks!

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Sep 16, 2016 @ 06:46
    Dave Woestenborghs
    0

    Hi,

    My first question : What is Vault ?

    Dave

  • Siavash Mortazavi 24 posts 145 karma points
    Sep 16, 2016 @ 13:08
    Siavash Mortazavi
    0

    Hi Dave,

    Vault is an Umbraco package, that lets us have MVC-like ViewModels instead of accessing page properties data by Umbraco API. https://github.com/thenerdery/UmbracoVault

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Sep 16, 2016 @ 13:57
    Dave Woestenborghs
    0

    Hi Siavash,

    Never heard of it. It is also not listed on our.umbraco.org in the projects section. So I don't know if people have a lot of experience with it as it is unknown to biggest part of the community.

    If you want to have strongly typed models representing your doctypes have a look at the Models builder that is shipped with Umbraco since 7.4.x

    In my opinion it's better to use the core stuff than something rather exotic.

    If you don't like the models builder Ditto is also a good option and is more widely known. So it's easier to get help.

    Dave

  • Siavash Mortazavi 24 posts 145 karma points
    Sep 18, 2016 @ 01:38
    Siavash Mortazavi
    0

    Thank you Dave,

    I will definitely check Models builder, thanks for letting me know.

    Cheers, Sia

Please Sign in or register to post replies

Write your reply to:

Draft