1
votes

In the past I have had some great experience with Umbraco 6 and Windsor Castle as IoC. After more then a year not working with Umbraco I thought let's see what 7 has got in store (I like the backoffice!)

After creating a new project and using NuGet to install Umbraco 7.2.1 I decided to implement Windsor Castle as of my experience in the past.

After installing the IoC and setting up the installconfig my backoffice won't load anymore! See the following error:

    Castle.MicroKernel.ComponentNotFoundException was unhandled by user code
    HelpLink=groups.google.com/group/castle-project-users
    HResult=-2146233088
    Message=No component for supporting the service Umbraco.Web.Editors.AuthenticationController was found
    Source=Castle.Windsor
    StackTrace:
           at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy)
           at Castle.MicroKernel.DefaultKernel.Resolve(Type service, IDictionary arguments)
           at Castle.Windsor.WindsorContainer.Resolve(Type service)
           at Project.Composition.ObjectFactory.Resolve(Type type) in c:\Repositories\Project\1. Code\Project\Composition\ObjectFactory.cs:regel 24
           at Project.Web.Composition.WindsorCompositionRoot.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType) in c:\Repositories\Project\1. Code\Project.web\Composition\WindsorCompositionRoot.cs:regel 22
           at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)
           at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncInternal(HttpRequestMessage request, CancellationToken cancellationToken)
           at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    InnerException: null

I just can't figure out what is happening or what the problem is. I only have this when I load the backoffice. It crashes already in the inlog screen. I have already tried several thing: Umbraco MVC with Castle Windsor https://gist.github.com/florisrobbemont/5821863 But I just can't figure it out.

edit 04-02-2015 ---->

This https://gist.github.com/florisrobbemont/5821863 is more or less what I used! What do you want to see more? My web.config the installers?

This is my boot class:

public class UmbracoBoot : IApplicationEventHandler
    {
        internal static IWindsorContainer Container;

        public void OnApplicationInitialized(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            umbracoApplication.Disposed += umbracoApplication_Disposed;
        }

        void umbracoApplication_Disposed(object sender, System.EventArgs e)
        {
            Application.Stop();
        }

        protected void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            Container = new WindsorContainer()
                .Install(Configuration.FromAppConfig())
                .Register(Classes.FromThisAssembly().BasedOn<IController>().LifestyleTransient());

            FilteredControllerFactoriesResolver.Current.InsertType<UmbracoFilteredControllerFactory>(0);
        }

        public void OnApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            RouteConfig.Register();
            FilterConfig.Register();
            BundleConfig.Register();
        }

        public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
        {
            Application.Create();
            FilteredControllerFactoriesResolver.Current.InsertType<UmbracoFilteredControllerFactory>(0);
            DependencyResolver.SetResolver(new WindsorDependencyResolver(Application.ObjectFactory));
            GlobalConfiguration.Configuration.Services.Replace(typeof(IHttpControllerActivator), new WindsorCompositionRoot(Application.ObjectFactory));

            Application.Start();
        }
    }
2
"setting up the installconfig" Could you elaborate? Show us the code/config? The problem is that Castle Windsor doesn't find a registration so I guess that maybe you are not setting up all componentssamy
I have added my boot class, do you need anything more? I mostly used this link gist.github.com/florisrobbemont/5821863Melvin
Also when I go to a page it self like home or something, the IoC works like a charm, but when I navigate to /umbraco/ it crashes!Melvin

2 Answers

0
votes

I might be wrong, but it seems to me that you are installing all controller from your application with this line:

.Register(Classes.FromThisAssembly().BasedOn<IController>().LifestyleTransient());

but your Umbraco.Web.Editors.AuthenticationController is probably in a different assembly. Try registering it explicitly, or if you need register all Controller from that assembly using Classes.FromAssemblyContaining (might be mistaken by the exact function name).

Goodluck, Marwijn.

0
votes

I had a similar problem and use the technique described for structuremap here http://www.wearesicc.com/getting-started-with-umbraco-7-and-structuremap-v3/

I've adjusted my WindsorCompositionRoot class Create method to check if the request is for an umbraco controller, and if it is, let Umbraco resolve it. Method now looks like this:

        public IHttpController Create(HttpRequestMessage request,
                                        HttpControllerDescriptor controllerDescriptor,
                                        Type controllerType)
        {
            if (ControllersHelper.IsUmbracoController(controllerType))
            {
                return Activator.CreateInstance(controllerType) as IHttpController;
            }

            var controller = (IHttpController)_container.Kernel.Resolve(controllerType);

            request.RegisterForDispose(new Release(() => _container.Kernel.ReleaseComponent(controller)));

            return controller;
        }

using the IsUmbracoController method from the linked post.