V
V
Vladislav Kilin2013-12-03 13:01:23
Design patterns
Vladislav Kilin, 2013-12-03 13:01:23

Registering dependencies from other assemblies in CastleWindsor?

I use the latest version of CastleWindsor as an IoC container in my project. Project under MVC4, SOA is used. The project already at the alpha testing stage has a lot of functionality and code, for further extensibility, many parts of the code are separated not only for different projects, but even for different solutions.
Thus, when registering the dependencies of UI solutions, you have to pull these dependencies from third-party assemblies. Are there any solutions that would be better than mine?
My Solution
There is a static class in the CoreFramework of the application

public static class AssemblyNamesRepository
    {
        private static readonly string[] assemblyNames = new[]
                                                             {
                                                                 "Core", "BusinessObjects", "UserServices",
                                                                 "ModuleServices", "CharacterServices",
                                                                 "RoomServices", "ReaderServices", "CommentServices",
                                                                 "PostServices", "AttributesServices", "BaseSite"
                                                             };

        public static IEnumerable<string> SelectAll()
        {
            return assemblyNames;
        }
    }

Accordingly, when installing the container, I do something like this:
foreach (var assemblyName in AssemblyNamesRepository.SelectAll())
                container.Register(
                    Types.FromAssemblyNamed(assemblyName)
                        .Where(t => t.IsClass)
                        .Configure(t => t.LifestylePerWebRequest())
                        .WithService.AllInterfaces());

It is clear that I have to face such a problem: as soon as I add a new service, I definitely need to duplicate it in the AssemblyNamesRepository class.
The idea looks like another post-build event to write the name of the assembly to some file, and then read the list of assemblies from this file. However, I have no idea how to do this.
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Kilin, 2013-12-27
@Quilin

I solved the problem through the xml-file with the topology settings. One way or another, I had to bind each service to its port, and describe a few more little things for each service. At the same time I decided to store the name of the assembly in this file. Now, at the start of the application, I simply read these AssemblyNames from the file, and then I do everything the same way.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question