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!
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.
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:
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!
Hi,
My first question : What is Vault ?
Dave
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
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
Thank you Dave,
I will definitely check Models builder, thanks for letting me know.
Cheers, Sia
is working on a reply...