unused classes?

Jul 9, 2009 at 8:56 AM

There are a bunch of classes and they are used nowhere

under KIGG\Core\Repository\Decorated :

  • DecoratedCategoryRepository
  • DecoratedStoryRepository
  • DecoratedUserRepository
  • DecoratedTagRepository

under KIGG\Core\Repository\Decorated\Logging :

  • LoggingCategoryRepository
  • LoggingStoryRepository
  • LoggingUserRepository
  • LoggingTagRepository

under KIGG\Core\Repository\Decorated\Caching :

  • CachingategoryRepository
  • CachingStoryRepository
  • CachingUserRepository
  • CachingTagRepository

Can someone shed some light on this?

Thanks

Coordinator
Jul 9, 2009 at 12:48 PM

These classes are used. In Web.config you'll find that they are configured to be used as default by IoC container.

Jul 9, 2009 at 7:33 PM

Thanks Mosses
That's true that they are referenced in the Unity section of Web.config
That's means that they are instantied by IoC but still I cannot see any place where they are really used

Sorry but it is still not clear for me
Can you clarify?

Coordinator
Jul 11, 2009 at 2:32 AM

Caching in KiGG is applied through Decorator Pattern, same thing for logging. Those repositories Prefixed with Caching or Logging apply decorator pattern. You can exmin the classes code and read about decorator pattern to know more about how it works.

Now KiGG by default delegates all instantiation to IoC. Now for those classes such as CachingCategoryRepository they are used as default mapping for IXxxRepository interfaces. Default mapping has no name attribute. Caching repositories as it applies Decorator pattern, it has dependency on another ICategoryRepository, for example CachingCategoryRepository constructor accepts ICategoryRepository as parameter. This dependency is defined in the mapping and it targets LoggingCategoryRepository, You can review it on configuration.

Same thing applies for LoggingCategoryRepository, in mapping configuration its dependecy is mapped to CategoryRepository.

So now, when a controller needs a repository such as ICategoryRepository, IoC is responsible for instantiating new or returning exising instance of ICategoryRepository. And by default it will return CachingCategoryRepository (as mentioned above it is default mapping). And because CachingCategoryRepository is configured to accept LoggingCategoryRepository as parameter, IoC also when constructing the CachingCategoryRepository it will pass a LogginCategoryRepository to it. An so on.

I hope this idea is cleared to you now! let me know if you have anything not clear. I might try to explain it better.

<type type="ICategoryRepository" mapTo="CachingCategoryRepository">
            <lifetime type="PerWebRequest"/>
            <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
              <constructor>
                <param name="innerRepository" parameterType="ICategoryRepository">
                  <dependency name="Logging"/>
                </param>
                <param name="cacheDurationInMinutes" parameterType="System.Single">
                  <!---Cache for 7 Days -->
                  <value type="System.Single" value="10080"/>
                </param>
              </constructor>
            </typeConfig>
          </type>
<type type="ICategoryRepository" mapTo="CachingCategoryRepository">
            <lifetime type="PerWebRequest"/>
            <typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
              <constructor>
                <param name="innerRepository" parameterType="ICategoryRepository">
                  <dependency name="Logging"/>
                </param>
                <param name="cacheDurationInMinutes" parameterType="System.Single">
                  <!---Cache for 7 Days -->
                  <value type="System.Single" value="10080"/>
                </param>
              </constructor>
            </typeConfig>
          </type>
Jul 11, 2009 at 8:25 AM

Oh Mosses thank you so much
I just realized that IXXXRepository is mapped to CachingXXXRepository
This last one has a dependency with LoggingXXXReository which, at its turn, has a depency with XXXRepository
Everything is vey clear to me now and thank you so much again

I am from on old school and all this is very new to me
I learned and I am still learning a lot from this project

I really do appreciate your great work here

Coordinator
Jul 12, 2009 at 9:50 AM

@nachid Don't worry, at the beginning I had same confusion until I explored the whole code step by step to cover all missing points for me in order to get evolved in it.

Great the the point is clear now. This discussion it great because we clarified the usage of those classes and the usage of decorator pattern.

Jul 12, 2009 at 3:36 PM

I would just like to add a big Thank You as discussions like this are invaluable to me in learning not only KiGG but MVC in general.

John Tarbox