I'm trying to implement IHandlerSelector and am encountering what
seems to me like strange behavior. The HasOpinionAbout and
SelectHandler methods never get both the key AND the service. When
they get a key, the service is System.Object, and when they get a
service the key is null. Am I doing something wrong?

Here's my code:
First, the IHandlerSelector implementation:

internal class RepositoryHandlerSelector : IHandlerSelector
    {
        private static readonly string
writeRepositoryInterfaceTypeName = typeof(IWriteRepository<>).Name;

        public bool HasOpinionAbout(string key, Type service)
        {
            return string.IsNullOrEmpty(key) && service.Name ==
writeRepositoryInterfaceTypeName;
        }

        public IHandler SelectHandler(string key, Type service,
IHandler[] handlers)
        {
            return handlers.FirstOrDefault(handler => !
handler.ComponentModel.Implementation.Name.EndsWith("Decorator"));
        }
    }


Next, the relevant parts of the wiring:

container.Kernel.AddHandlerSelector(new RepositoryHandlerSelector());

container.Register
                (
                    AllTypes.FromAssembly(assembly)
                    .IncludeNonPublicTypes()
                    .BasedOn(typeof(IWriteRepository<>)).WithService.Base()
                    .Configure(component =>
component.LifeStyle.Transient)
                );
container.Register
            (
                Component.For(typeof(IWriteRepository<>))
                .ImplementedBy(typeof(SecurityRepositoryDecorator<>))
                .Named("securityDecorator")
                .Parameters(Parameter.ForKey("inner").Eq("$
{transactionDecorator}"))
            );
container.Register
            (
                Component.For(typeof(IWriteRepository<>))
                .ImplementedBy(typeof(TransactativeRepositoryDecorator<>))
                .Named("transactionDecorator")
            );

// test
var repository =
container.Resolve<IWriteRepository<Document>>("securityDecorator");


When the line under test is run, is where I'm getting the above-
mentioned phenomena.
Any ideas?


Joni

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to