5 Replies - 479 Views - Last Post: 27 April 2013 - 08:34 AM Rate Topic: -----

#1 ray1234  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 07-September 12

registering types at the root using IOC

Posted 25 April 2013 - 09:12 AM

i'm trying to register all components when my application start, and resolve the required components when a HTTP request is made to a particular controller in MVC.

So far my routing works fine, and It resolves the correct controller instance needed. so if the url has a Home/Index, it finds Home controller and executes the algorithm in index method.

the issue i'm getting is that the bottstrapper method called in application start. it doesn't register my installers from referenced assembly called (configuration)

  protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);

             

            BootstrapContainer();
           
        }

        private void BootstrapContainer() 
        {

            Container = new WindsorContainer().Install(FromAssembly.This(), FromAssembly.Named("Configuration"));
            var controllerFactory = new WindsorControllerFactory(Container.Kernel);  // resolves the controller based on controller
            ControllerBuilder.Current.SetControllerFactory(controllerFactory); 
        }



Container = new WindsorContainer().Install(FromAssembly.This(), FromAssembly.Named("Configuration"));



this statement above locates the installer from configuration assembly correctly but after registering the classes within the installer method. It does not add to the overall container.

  public class BLinstaller : IWindsorInstaller
    {
       
        public void Install(IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
        {
            container.Register(Classes.FromAssemblyNamed("Application_Service_Layer"));

        }
    }



any ideas on why these claases on the above method are not added to my container after registering?


what I want to achieve is a container object, which contains all the registered components. so that when a controller is reolved all its dependencies are resolved too

This post has been edited by ray1234: 25 April 2013 - 09:13 AM


Is This A Good Question/Topic? 0
  • +

Replies To: registering types at the root using IOC

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: registering types at the root using IOC

Posted 25 April 2013 - 09:28 AM

Are you saying that BLinstaller.Install() method is not being called even though,
Container = new WindsorContainer().Install(FromAssembly.This(), FromAssembly.Named("Configuration"));


succeeds?

Is there a way you can turn on logging for Windsor to see what it is doing? If you can't turn on logging, you could always trace into the code and see what is happening. It is open source after all.
Was This Post Helpful? 0
  • +
  • -

#3 ray1234  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 07-September 12

Re: registering types at the root using IOC

Posted 25 April 2013 - 10:52 AM

View PostSkydiver, on 25 April 2013 - 04:28 PM, said:

Are you saying that BLinstaller.Install() method is not being called even though,
Container = new WindsorContainer().Install(FromAssembly.This(), FromAssembly.Named("Configuration"));


succeeds?

Is there a way you can turn on logging for Windsor to see what it is doing? If you can't turn on logging, you could always trace into the code and see what is happening. It is open source after all.


thanks for your quick response.

BLinstaller.install method is called. but when it executes the statement.

container.Register(Classes.FromAssemblyNamed("Application_Service_Layer")); 



the container doesn't hold any types for the assembly, when it should. The statement clearly executes meaning it does find that assembly. I made sure that the types all match the namespace correctly and that they were public accessor

This post has been edited by ray1234: 25 April 2013 - 10:53 AM

Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: registering types at the root using IOC

Posted 25 April 2013 - 11:46 AM

What assurance do you have that the container object you got back on line 18 of BootstrapContainer() is the same one being passed in to BLinstaller.Install() ?
Was This Post Helpful? 0
  • +
  • -

#5 ray1234  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 07-September 12

Re: registering types at the root using IOC

Posted 26 April 2013 - 08:47 AM

View PostSkydiver, on 25 April 2013 - 06:46 PM, said:

What assurance do you have that the container object you got back on line 18 of BootstrapContainer() is the same one being passed in to BLinstaller.Install() ?



through debugging. the statement first retrives the installers from the (fromassembly.this()), then it enters the BL installer method in configuration assembly. The parameter container of the installer method holds the types from the first execution. after executing blinstaller and returning to line 18 of bootstrapcontainer method. the container property only shows types executed from first call but not the call to BLinstaller. so when I go container.register in blinstaller. insteading of adding types to that container it doesn't do it.

Container = new WindsorContainer().Install(FromAssembly.This(), FromAssembly.Named("Configuration"));


Was This Post Helpful? 0
  • +
  • -

#6 ray1234  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 148
  • Joined: 07-September 12

Re: registering types at the root using IOC

Posted 27 April 2013 - 08:34 AM

after further investigation, I manage to solve this, by having to specify the types lifestyle being registered.

so;

  public class ControllerInstaller : IWindsorInstaller
    {
        public void Install(IWindsorContainer container, IConfigurationStore store)
        {
            container.Register(Classes.FromThisAssembly()
                .BasedOn<IController>()
                .LifestyleTransient());
            
        }
    }


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1