Windsor Container: Registering Things in Code vs Xml

From what I read about Windsor / Microkernel, it is theoretically possible to do everything you can do using xml files with code. Actually - and please correct me if I am wrong. - it seems that the main contribution of the Windsor layer is the addition of an XML configuration for things Microkernels can already be done

However, I have been struggling lately to figure out how to implement some slightly more complex functionality in the code though (i.e.. How to assign a default constructor to the argument value ). Now that I'm going to use xml in my release, I am registering the components in the code for their tests, and this becomes quite problematic. This is not helped by the sad state of their documentation and the fact that the only articles I can find are focused on xml registration.

Does anyone know a source that lists how to register things in code (preferably with the equivalent xml)? Hiding this, does anyone just know an open source / sample project where there is significant use of non-xml Castle Windsor / Microkernel?

+4
source share
1 answer

I have always been looking for unit test the best way to find out how to use an open source project. The lock has a free interface that allows you to do everything in code. From WindsorDotNet2Tests test case:

[Test] public void ParentResolverIntercetorShouldNotAffectGenericComponentInterceptor() { WindsorContainer container = new WindsorContainer(); container.AddComponent<MyInterceptor>(); container.Register( Component.For<ISpecification>() .ImplementedBy<MySpecification>() .Interceptors(new InterceptorReference(typeof(MyInterceptor))) .Anywhere ); container.AddComponent("repos", typeof(IRepository<>), typeof(TransientRepository<>)); ISpecification specification = container.Resolve<ISpecification>(); bool isProxy = specification.Repository.GetType().FullName.Contains("Proxy"); Assert.IsFalse(isProxy); } 

And for more, check out ComponentRegistrationTestCase and AllTypesTestCase

There is also a DSL for this, this is my preferred option as it really simplifies things and offers a lot of expansion options. The DSL is called Binsor, which you can read about here: http://www.ayende.com/Blog/archive/7268.aspx But again, Unit Tests is the best place for information. This is an example of code that can be used with a binsor:

 for type in AllTypesBased of IController("Company.Web.Controller"): component type 

These two lines will ever register a type that inherits the IController interface in the container: D

+6
source

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


All Articles