Breaking change to Kernels registration fluent interface

2 views
Skip to first unread message

Craig Neuwirt

unread,
Feb 9, 2008, 3:53:02 PM2/9/08
to castle-pro...@googlegroups.com
The fluent interface registration interface change to the following syntax

            kernel.Register(
                Component.ForService<ICustomer>()
                    .Named("customer1")
                    .ImplementedBy<CustomerImpl>()
                    .CustomDependencies(
                        Property.ForKey("Name").Eq("Caption Hook"),
                        Property.ForKey("Address").Eq("Fairyland"),
                        Property.ForKey("Age").Eq(45)
                        ),
                Component.ForService<CustomerChain1>()
                    .Named("customer2")
                    .CustomDependencies(
                        Property.ForKey("Name").Eq("Bigfoot"),
                        Property.ForKey("Address").Eq("Forest"),
                        Property.ForKey("Age").Eq(100)
                        )
                    .ServiceOverrides(
                        ServiceOverride.ForKey("customer").Eq("customer1")
                        )
                );

This was done for the following reasons
  • Be a little more readable
  • Better support multiple registrations in a single call
  • Prevent the common error of filling out the registration fluent interface, but forgetting to call register
This is a breaking change, but this registrstion is fairly new so it shouldn't have a huge impace

craig

Ayende Rahien

unread,
Feb 9, 2008, 4:12:09 PM2/9/08
to castle-pro...@googlegroups.com
Looking really nice.

Craig Neuwirt

unread,
Feb 9, 2008, 5:00:05 PM2/9/08
to castle-pro...@googlegroups.com
Thanks, it is now ready to plug into binsor so all registrations with be based on a single registration and offer a few more capabilities.

Hamilton Verissimo

unread,
Feb 9, 2008, 5:44:23 PM2/9/08
to castle-pro...@googlegroups.com
Excellent. It has been asked on the user list, is it possible to pass
arrays and/or dictionaries?

On 2/9/08, Craig Neuwirt <cneu...@gmail.com> wrote:


--
Cheers,
hamilton verissimo
ham...@castlestronghold.com
http://www.castlestronghold.com/

Craig Neuwirt

unread,
Feb 10, 2008, 11:08:34 AM2/10/08
to castle-pro...@googlegroups.com
Hey Hammett,

  I didn't realize I wasn't receiving emails for the users list.  I know am and will respond to them accordingly.

As for the question, any arrays, lists or dictionaries are supported using custom depenedencies unless they are service overrides.
I updated the service overrides support for the fluent registration to handles arrays/lists of service overrides.  To handle complex scenarios like dictionaries, I also introduces a Parameters specification.  If the community really needs first class support for dictionaries with service overrides. I will add it.

Service Overrides for typed arrays example

            kernel.Register(
                Component.ForService<ICommon>()
                    .Named("common1")
                    .ImplementedBy<CommonImpl1>(),
                Component.ForService<ICommon>()
                    .Named("common2")
                    .ImplementedBy<CommonImpl2>(),
                Component.ForService<ClassWithArrayConstructor>()
                    .ServiceOverrides(
                        ServiceOverride.ForKey("first").Eq("common2"),
                        ServiceOverride.ForKey("services").Eq("common1", "common2")
                    )
                );

Service Overrides for untyped lists

             kernel.Register(
                Component.ForService<ICommon>()
                    .Named("common1")
                    .ImplementedBy<CommonImpl1>(),
                Component.ForService<ICommon>()
                    .Named("common2")
                    .ImplementedBy<CommonImpl2>(),
                Component.ForService<ClassWithListConstructor>()
                    .ServiceOverrides(
                        ServiceOverride.ForKey("services").Eq<ICommon>("common1", "common2")
                    )
                );
  
Here is the link to the units tests to demonstrate them all

http://svn.castleproject.org:8080/svn/castle/trunk/InversionOfControl/Castle.MicroKernel.Tests/Registration/ComponentRegistrationTestCase.cs

craig
Reply all
Reply to author
Forward
0 new messages