Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Design and Architecture
  4. Unity in Modular App

Unity in Modular App

Scheduled Pinned Locked Moved Design and Architecture
game-devdockerquestiondiscussion
16 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Pete OHanlon

    Nope, sorry - that didn't make much sense to me. Could you put a practical example here highlighting what you're trying to solve. BTW - don't forget - just because you have registered a child container in your module, this doesn't mean that the parent IUnityContainer is no longer available.

    This space for rent

    A Offline
    A Offline
    aboubkr90
    wrote on last edited by
    #7

    OK! // Registration phase 1. Manager creates a container and registers modules. 2. Manager passes a child container to every module to registers it's services. 3. Module1 register LegitLogger as ILogger. // Resolution 4. Manager passes root container to every module to able to find services added by other modules (on child containers). Without IServiceLocator wrap, Module2 can register DummyLogger as ILoger on the root container so that LegitLogger will never be found (child containers will not be searched). The only way of discovering the limits of the possible is to venture a little way past them into the impossible.

    P 1 Reply Last reply
    0
    • P Pete OHanlon

      Nope, sorry - that didn't make much sense to me. Could you put a practical example here highlighting what you're trying to solve. BTW - don't forget - just because you have registered a child container in your module, this doesn't mean that the parent IUnityContainer is no longer available.

      This space for rent

      A Offline
      A Offline
      aboubkr90
      wrote on last edited by
      #8

      As for what I'm trying to solve. In the current setup a module can only use it's services and the services registered on the root container, So modules cannot share there services. We could pass the root container to modules so they can register there services in a single pool, but then a module can intercept another module's services. The only way of discovering the limits of the possible is to venture a little way past them into the impossible.

      L 1 Reply Last reply
      0
      • A aboubkr90

        OK! // Registration phase 1. Manager creates a container and registers modules. 2. Manager passes a child container to every module to registers it's services. 3. Module1 register LegitLogger as ILogger. // Resolution 4. Manager passes root container to every module to able to find services added by other modules (on child containers). Without IServiceLocator wrap, Module2 can register DummyLogger as ILoger on the root container so that LegitLogger will never be found (child containers will not be searched). The only way of discovering the limits of the possible is to venture a little way past them into the impossible.

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #9

        I'm a touch confused as to why you think you need to pass the child container in. Remember that unity looks for modules that implement IModule - so, create a base module class that takes the parent container and creates a child container internally. Something like this:

        public abstract class ModuleBase : IModule
        {
        public IUnityContainer ParentContainer { get; private set; }

        public ModuleBase(IUnityContainer container)
        {
        ParentContainer = container;
        Container = container.CreateChildContainer();
        }
        }

        With that, you have a segregated module architecture that will allow you to set up the interfaces how you like. I would tend to create a fluent architecture here to simplify the registration in here, but that's just me.

        This space for rent

        A 1 Reply Last reply
        0
        • P Pete OHanlon

          I'm a touch confused as to why you think you need to pass the child container in. Remember that unity looks for modules that implement IModule - so, create a base module class that takes the parent container and creates a child container internally. Something like this:

          public abstract class ModuleBase : IModule
          {
          public IUnityContainer ParentContainer { get; private set; }

          public ModuleBase(IUnityContainer container)
          {
          ParentContainer = container;
          Container = container.CreateChildContainer();
          }
          }

          With that, you have a segregated module architecture that will allow you to set up the interfaces how you like. I would tend to create a fluent architecture here to simplify the registration in here, but that's just me.

          This space for rent

          A Offline
          A Offline
          aboubkr90
          wrote on last edited by
          #10

          In that setup the following code is possible:

          public class DefectiveModuel : IModule
          {
          public DefectiveModuel(IUnityContainer container)
          {
          // trash the container
          }
          }

          The setup I'm going for is more like:

          public interface IModule
          {
          void RegisterServices(IUnityContainer container);
          void Init(IUnityContainer container);
          }
          public class Manager
          {
          public void Init(IUnityContainer root)
          {
          // Do something with the container
          Modules.Foreach(m => m.RegisterServices(root.CreateChildContainer()));
          Modules.Foreach(m => m.Init(root.Wrap()));
          }
          }

          So modules will only be able to configure there child container. However, they will be able to use the root container to access services added by other modules on child containers under root.

          The only way of discovering the limits of the possible is to venture a little way past them into the impossible.

          P 1 Reply Last reply
          0
          • A aboubkr90

            In that setup the following code is possible:

            public class DefectiveModuel : IModule
            {
            public DefectiveModuel(IUnityContainer container)
            {
            // trash the container
            }
            }

            The setup I'm going for is more like:

            public interface IModule
            {
            void RegisterServices(IUnityContainer container);
            void Init(IUnityContainer container);
            }
            public class Manager
            {
            public void Init(IUnityContainer root)
            {
            // Do something with the container
            Modules.Foreach(m => m.RegisterServices(root.CreateChildContainer()));
            Modules.Foreach(m => m.Init(root.Wrap()));
            }
            }

            So modules will only be able to configure there child container. However, they will be able to use the root container to access services added by other modules on child containers under root.

            The only way of discovering the limits of the possible is to venture a little way past them into the impossible.

            P Offline
            P Offline
            Pete OHanlon
            wrote on last edited by
            #11

            Unfortunately, because the parent container is still available to you, there's nothing stopping the inner services from trashing the root container - all they need to do is get the Parent from your IUnityContainer; you're not going to be able to prevent that.

            This space for rent

            A 1 Reply Last reply
            0
            • P Pete OHanlon

              Unfortunately, because the parent container is still available to you, there's nothing stopping the inner services from trashing the root container - all they need to do is get the Parent from your IUnityContainer; you're not going to be able to prevent that.

              This space for rent

              A Offline
              A Offline
              aboubkr90
              wrote on last edited by
              #12

              :( Just noticed. Edit: However, It's still hard to predict the order in which the modules will be called. Edit2: If there was an IServiceRegister interface. Then we could use it to wrap the container during registration. "The only way of discovering the limits of the possible is to venture a little way past them into the impossible" Arthur C. Clarke

              P 1 Reply Last reply
              0
              • A aboubkr90

                As for what I'm trying to solve. In the current setup a module can only use it's services and the services registered on the root container, So modules cannot share there services. We could pass the root container to modules so they can register there services in a single pool, but then a module can intercept another module's services. The only way of discovering the limits of the possible is to venture a little way past them into the impossible.

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #13

                aboubkr90 wrote:

                The only way of discovering the limits of the possible is to venture a little way past them into the impossible.

                Please do not apply that philosophy to daily traffic.

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                A 1 Reply Last reply
                0
                • A aboubkr90

                  :( Just noticed. Edit: However, It's still hard to predict the order in which the modules will be called. Edit2: If there was an IServiceRegister interface. Then we could use it to wrap the container during registration. "The only way of discovering the limits of the possible is to venture a little way past them into the impossible" Arthur C. Clarke

                  P Offline
                  P Offline
                  Pete OHanlon
                  wrote on last edited by
                  #14

                  I have handled this, in the past, by hiding the module registration. This works by putting a proxy registrar in place and then exposing this through the module registration instead. At some point, I'll put out an article describing how I did this (part of the idea behind this is that this approach makes it easier to swap IoC containers around).

                  This space for rent

                  A 1 Reply Last reply
                  0
                  • P Pete OHanlon

                    I have handled this, in the past, by hiding the module registration. This works by putting a proxy registrar in place and then exposing this through the module registration instead. At some point, I'll put out an article describing how I did this (part of the idea behind this is that this approach makes it easier to swap IoC containers around).

                    This space for rent

                    A Offline
                    A Offline
                    aboubkr90
                    wrote on last edited by
                    #15

                    :thumbsup:Good idea. PS: I just thought of the idea of having to replace all those IUnityContainer references. That is one scary thought. ____________________________________________________________________________________________________ "The only way of discovering the limits of the possible is to venture a little way past them into the impossible" Arthur C. Clarke

                    1 Reply Last reply
                    0
                    • L Lost User

                      aboubkr90 wrote:

                      The only way of discovering the limits of the possible is to venture a little way past them into the impossible.

                      Please do not apply that philosophy to daily traffic.

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^][](X-Clacks-Overhead: GNU Terry Pratchett)

                      A Offline
                      A Offline
                      aboubkr90
                      wrote on last edited by
                      #16

                      Good thing i don't have a license. :-D ____________________________________________________________________________________________________ "The only way of discovering the limits of the possible is to venture a little way past them into the impossible" Arthur C. Clarke

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups