Kernel Component Registration Strategies

20 views
Skip to first unread message

Craig Neuwirt

unread,
Mar 1, 2008, 12:07:46 PM3/1/08
to castle-pro...@googlegroups.com
The recent changes to the kernel registration interface allows for custom registration strategies.   I just added an AllTypesOf strategy to allow for the most common scenarios. 

Here are some examples
  • registering all controllers in the current assembly 
    • kernel.Register( AllTypesOf<IController>
           .FromAssembly( Assembly.GetExecutingAssembly() )
            );
  • selecting the first interface as the service
    • kernel.Register( AllTypesOf<ICommon>
            .FromAssembly(Assembly.GetExecutingAssembly() )
            .WithService.FirstInterface()
             );
  • Using custom configuration
    • kernel.Register( AllTypesOf<ICommon>
            .FromAssembly( Assembly.GetExecutingAssembly() )
            .Configure( component => component.LifeStyle.Transient
                                  .Named( component.Implementation.FullName + "XYZ" )
                                  )
             );
  • Choosing types if they have a specific attribute (courtesy of LINQ)
    • kernel.Register( AllTypesOf<CustomerChain1>
              .Pick( from type in Assembly.GetExecutingAssembly().GetExportedTypes()
                       where type.IsDefined(typeof(SerializableAttribute), true)
                       select type
                       ));
Thanks to Ayende for inspiration from some of his Binsor work!!!

craig

Ayende Rahien

unread,
Mar 1, 2008, 2:01:44 PM3/1/08
to castle-pro...@googlegroups.com
You are taking all the fun out of Binsor :-)

Craig Neuwirt

unread,
Mar 1, 2008, 2:19:24 PM3/1/08
to castle-pro...@googlegroups.com
Oh no,

  It would take a lot more magic and probably c# 6.0 to be able to do that!!!  In fact, the registration updates had Binsor in mind.  I am going to replace all the custom extension stuff in Binsor with a single ComponentRegistration.  This will eliminate most of Binsor code and finally have a single unified registration approach so other tools besides boo and have some fun.  Gotta get my RhinoTools Nant building happily from trunk first :-)

How's Seattle treating you?

craig

Shawn Hinsey

unread,
Mar 1, 2008, 8:57:40 PM3/1/08
to castle-pro...@googlegroups.com
This is really cool. Awesome work.

On 3/1/08, Craig Neuwirt <cneu...@gmail.com> wrote:

Ümit Akbaş

unread,
Nov 24, 2015, 6:09:47 AM11/24/15
to Castle Project Development List, smhi...@gmail.com
Hi , first of all it is nice work. !! Thank you.
I have a question about binsor to optimize register components text format in boo files.

I want to use this code block in my boo files : 

"var kernel = new DefaultKernel();
using (kernel.OptimizeDependencyResolution())
{
for (int i = 0; i < 500; i++)
{
kernel.AddComponent("key" + i, typeof(string), typeof(string));
}
}
"
below you can see my boo code.
"private def RegisterRepositories():
   for type in AllTypes("<myAssebmly>"):
       continue unless typeof(cr.IRepositoryBase).IsAssignableFrom(type)
       keyType = TypeHelper.GetTopLevelRepositoryInterface(type)
       if not Kernel.HasComponent(keyType):
           Component type.Namespace + "." + type.Name.ToLowerInvariant() + ".repository", keyType, type
"

how can i you "using" c# keyword in my case. 
i'll be happy with your helps.

Thanx...

Ümit

2 Mart 2008 Pazar 03:57:40 UTC+2 tarihinde Shawn Hinsey yazdı:
Reply all
Reply to author
Forward
0 new messages