ComponentNotFoundException when using TypedFactoryFacility

1,302 views
Skip to first unread message

Matthew Brubaker

unread,
Sep 29, 2011, 5:26:02 PM9/29/11
to Castle Project Users
I am currently using Castle.Widsor v3.0 Beta 1.
The code I am having problems with at the moment is

var _container = new WindsorContainer();

_container.AddFacility<TypedFactoryFacility>();

_container.Register(Component.For<IFileWatcher>().ImplementedBy<FileWatcher>().LifestyleTransient());

_container.Register(Component.For<IFileWatcherFactory>().AsFactory(x
=> x.SelectedWith(new FileWatcherSelector())));

var _fwf = _container.Resolve<IFileWatcherFactory>();
var fw = _fwf.GetFileWatcher(".\\bob.txt", 20);

The signature of IFileWatcherFactory.GetFileWatcher is

IFileWatcher GetFileWatcher(string filePath, int
sleepIntervalInSeconds);

this throws the following exception

Castle.MicroKernel.ComponentNotFoundException : No component
for supporting the service IFileWatcher was found

I have double checked all of the namespaces, usings, etc... and have
been unable to make any progress. This worked correctly as written
using Castle.Windsor v2.5.1 but stopped when I upgraded to v3.0.

Any help would be greatly appreciated. If further information is
needed, please let me know and I will do my best to provide it.

Krzysztof Koźmic

unread,
Sep 29, 2011, 7:08:38 PM9/29/11
to castle-pro...@googlegroups.com
Hi Matthew,

Could you isolate this into a failing unit test?

cheers,
Krzysztof

Matthew Brubaker

unread,
Sep 29, 2011, 8:40:17 PM9/29/11
to castle-pro...@googlegroups.com
unfortunately, that is the unit test that i have that's failing. I'm not sure how to isolate it down any further. The TypedFactoryFacility is the only facility in use and the two components are the only two things I am registering in the container.

Matthew Brubaker
MatthewS...@gmail.com
(785) 215-7061


2011/9/29 Krzysztof Koźmic <krzyszto...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.


Krzysztof Koźmic

unread,
Sep 29, 2011, 8:44:53 PM9/29/11
to castle-pro...@googlegroups.com
can you post the entire test
2011/9/29 Krzysztof Koźmic <krzyszto...@gmail.com>
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.

Matthew Brubaker

unread,
Sep 29, 2011, 9:38:59 PM9/29/11
to castle-pro...@googlegroups.com
The testing framework being used is NUnit, the Test Fixture and the related interfaces are below

    [TestFixture()]
    public class FileWatchersAndContainers
    {

        private WindsorContainer _container;
        private IFileWatcherFactory _fwf;

        [SetUp()]
        public void Setup()
        {
            //NOTE: container had to create the instance to 
            //NOTE: be aware that it should tear it down.
            _container = new WindsorContainer();

            _container.AddFacility<TypedFactoryFacility>();
            _container.Register(Component.For<IFileWatcher>().ImplementedBy<FileWatcher>().LifestyleTransient());
            _container.Register(Component.For<IFileWatcherFactory>().AsFactory(x => x.SelectedWith(new FileWatcherSelector())));
        }

        [Test()]
        public void SetUpAndTest()
        {
            _fwf = _container.Resolve<IFileWatcherFactory>();
            var fw = _fwf.GetFileWatcher(".\\bob.txt", 20);

            fw.StartWatching();
            Assert.IsTrue(fw.IsWatching);

            _container.Dispose();
            Assert.IsFalse(fw.IsWatching, "Should have been stopped");
        }
    }
}



    public interface IFileWatcherFactory : IDisposable
    {
        IFileWatcher GetFileWatcher(string filePath, int sleepIntervalInSeconds);
        void Destroy(IFileWatcher fw);
    }


    public interface IFileWatcher : IDisposable
    {
        string FilePath { get; }
        event FileWatcher.FileFoundEventHandler FileFound;
        
        void StartWatching();
        void StopWatching();
        bool IsWatching { get; }
    }

Krzysztof Koźmic

unread,
Sep 29, 2011, 10:45:32 PM9/29/11
to castle-pro...@googlegroups.com
Can you paste the selector and interface impl. as well?

cheers,
Krzysztof

Matthew Brubaker

unread,
Sep 29, 2011, 10:50:33 PM9/29/11
to castle-pro...@googlegroups.com
the only interface implementation i have is the one for the IFileWatcher. it is pretty long, is there a particular part of it you want?


    public class FileWatcherSelector : DefaultTypedFactoryComponentSelector
    {

        protected override string GetComponentName(MethodInfo method, object[] arguments)
        {
            if (method.Name == "GetFileWatcher" && arguments.Length == 2)
            {
                var fileName = Convert.ToString(arguments[0]);
                var scrubbedName = fileName.Replace('\\', '_').Replace(':', '_').Replace(' ', '_');

                return "watching.{0}".FormatWith(scrubbedName);
            }

            return base.GetComponentName(method, arguments);
        }
    }

Matthew Brubaker
MatthewS...@gmail.com
(785) 215-7061


2011/9/29 Krzysztof Koźmic <krzyszto...@gmail.com>
Can you paste the selector and interface impl. as well?
--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-project-users@googlegroups.com.
To unsubscribe from this group, send email to castle-project-users+unsub...@googlegroups.com.

Krzysztof Koźmic

unread,
Sep 29, 2011, 11:02:06 PM9/29/11
to castle-pro...@googlegroups.com
Ok, that's fine.

There are two parts to it. First of all the exception message you're
getting is misleading. In beta 2 and further on its actually:

Castle.MicroKernel.ComponentNotFoundException : Requested component
named 'watching.._bob.txt' was not found in the container. Did you
forget to register it?
There is one other component supporting requested service
'Foo.Bar.IFileWatcher'. Is it what you were looking for?

Second part of the issue is, as mentioned in the exception message,
you're trying to resolve the component by name, and there's no component
for that name.

This is a breaking change from v2.5.3 and as described in
breakingchanges.txt, if you want to fallback to resolving by type when
you can't resolve by name set
FallbackToResolveByTypeIfNameNotFound = true;
in your selector.

HTH,
cheers,
Krzysztof

Matthew Brubaker

unread,
Sep 29, 2011, 11:14:11 PM9/29/11
to castle-pro...@googlegroups.com
Thanks, I set FallbackToResolveByTypeIfNameNotFound to true and that fixed the problem. I thought I had searched through all of the breaking changes that were included in the nuget package for Castle.Windsor.3.0.0.2001and couldn't find anything relating to that property.


2011/9/29 Krzysztof Koźmic <krzyszto...@gmail.com>
Ok, that's fine.

Krzysztof Koźmic

unread,
Sep 30, 2011, 1:40:42 AM9/30/11
to castle-pro...@googlegroups.com
Hi Matthew,

you're right, it's not in breakingchanges.txt.

I'll add that for beta 2... it must have slipped through the cracks. Thanks for pointing that out.

cheers,
Krzysztof
2011/9/29 Krzysztof Koźmic <krzyszto...@gmail.com>
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group.
To post to this group, send email to castle-pro...@googlegroups.com.
To unsubscribe from this group, send email to castle-project-u...@googlegroups.com.

Matthew Brubaker

unread,
Sep 30, 2011, 1:53:39 AM9/30/11
to castle-pro...@googlegroups.com
Do you have any idea when the release for 3.0 will be? i'm currently in the process of integrating it into several of our projects at work and was hoping the nuget package would have the release soon.
2011/9/30 Krzysztof Koźmic <krzyszto...@gmail.com>

Krzysztof Koźmic

unread,
Sep 30, 2011, 2:27:21 AM9/30/11
to castle-pro...@googlegroups.com
Depends on my spare time, amount of bugs reported and community contributions.

Plan is to have RTM within a month.

Krzysztof

Krzysztof Koźmic

unread,
Sep 30, 2011, 2:30:01 AM9/30/11
to castle-pro...@googlegroups.com
BTW,

nuget package for v3b1 has been out for a few weeks already, it's just not a "recomended version". If you use nuget from command line that's what it'll update to.


On 30/09/2011 3:53 PM, Matthew Brubaker wrote:

Krzysztof Koźmic

unread,
Jan 18, 2012, 8:10:31 PM1/18/12
to castle-pro...@googlegroups.com
Hi Matthew,

Could you isolate this into a failing unit test?

cheers,
Krzysztof

On 30/09/2011 7:26 AM, Matthew Brubaker wrote:

Reply all
Reply to author
Forward
0 new messages