Can someone explain how Castle Windsor works in my application?

I started using Castle Windsor, and somehow my application works, but I really don’t understand how it works. Do not direct me to the documentation, as I will not be here.

In my Global.asax.cs I have this:

private static IWindsorContainer container;

protected void Application_Start()
{
  AreaRegistration.RegisterAllAreas();
  RegisterRoutes(RouteTable.Routes);
  BootstrapContainer();
} 

protected void Application_End()
{
  container.Dispose();
}

private static void BootstrapContainer()
{
 container = new WindsorContainer()
                .Install(FromAssembly.This());

 var controllerFactory = new WindsorControllerFactory(container.Kernel);
 ControllerBuilder.Current.SetControllerFactory(controllerFactory);
}

Now this is registering a new factory controller, which I understand. Installing WindsorContainer from the current build, I think, registers all installers, for example, I have a repository installer. I assume that the container created in Global.asax is passed to the installers.

public class RepositoriesInstaller : IWindsorInstaller
{
     public void Install(IWindsorContainer container, IConfigurationStore store)
    {

        container.Register(AllTypes.FromThisAssembly()
                 .Where(type => type.Name.EndsWith("Repository"))
                 .WithService.DefaultInterface()
                 .Configure(c => c.LifeStyle.PerWebRequest));
    }
}

In my controller, I created a constructor and passed it in an IRepository argument. I do not understand how the controller accepts this argument.

-, 2 , IRepository. , . , , IRepository, ?

Fluent NHibernate. , IRepository ISession. ?

+3
1

factory, Windsor, Windsor IoC .

, URL- MVC, "" "HomeController", WindsorControllerFactory MVC HomeController.

, IRepository, IRepository , Windsor , HomeController. IRepository - , HomeController, HomeController MVC.

IRepository (, UserRepository ProductRepository), , IRepository, :

public interface IProfileRepository : IRepository {}

API Windsor , IRepository, , , . IProfileRepository.

, Windsor , IRepository , .

, ISession, . , , ( ). , , .

, , :

  • ( ), Windsor, Windsor .

  • ISession Windsor factory , .

+6

Source: https://habr.com/ru/post/1785183/


All Articles