Introduction
In part 2, we explored KiGG project structure. I gave a short brief and summary about each project in the solution. And briefly discussed the relation between them.
In this part we are going to start going much deeper. Staring with the Core, and this might take several parts by itself as the Core is huge and contains lots of stuff that worth to be discussed.
Namespaces
Before starting it worth to mention that the core is free of any default implementation that depends on and external or third party assemblies. Now I’m going to start by listing namespaces inside Kigg.Core project with brief of each namespace:
- Kigg: The root namespace. This namespace is the default namespace. Contains all common classes that might be needed for other namespaces including extensions, utilities and helpers.
- Kigg.DomainObjects: This is the domain model namespace. Interfaces for all domain classes are defined in this namespace; e.g. IStory, ICategory, IUser etc...
- Kigg.Infrastructure: Infrastructure root namespaces. Contains infrastructure application support classes and interfaces that when implemented will provide specific infrastructure implementation. Such as event aggregation, logging and caching. Logging and caching are defined as interfaces. However basic implementation is done with Enterprise library caching and logging application blocks. These implementations are located in different assembly. As mentioned above, the core is free of any default implementation that depends on and external or third party assemblies.
- Kigg.Repository: Inside this namespace, all possible repositories that will be used across the application are defined as interfaces with no specific implementation. Except for decorator repositories (applying Decorator Pattern) which are used to apply caching and logging.
- Kigg.Service: Common services used by different kigg sections. Services consumes repositories and infrastructure.
- Kigg.Infrastructure.DomainRepositoryExtensions: This is a bridge assembly between DomainObjects and Repositories. Repositories usually returns instances of interfaces defined under DomainObjects namespace. At the same time, Domain objects might need to perform few operation based on data provided by repositories. To remove direct dependency from domain objects to repositories few extension methods made for specific domain objects. These extension methods access the repositories.
Extensions
KiGG provide sets of utilities and extensions that encapsulate common functionalities. As these stuff should be available to every project that references Core project it is added within the Core. And because it should be available to all namespaces implicitly, it is added to the root namespace Kigg.
Few examples of extensions to .Net System libraries are:
- EnumerableExtension: Provides extension methods to any IEnumerable<T>. e.g. ForEach extension method that acts as simple shortcut for foreach loop.
- CollectionExtension: Provides extension methods to any ICollection<T>. e.g. IsNullOrEmpty extension methods that check if the collection is null or has no items (empty).
There are some other extensions for .Net System classes that you can explore.
Another extensions are provided for Domain Objects. Because these extensions are related only to DomainObjects, they are located under Kigg.DomainObjects. These extensions are:
- StoryExtension: Contains few helpful extensions such as IsNew which checks if the story is new or not. Another extension SmallThumbnail that consumes the IThumbnail to generate a small thumb snapshot image of the story web page.
- UserExtension: Contains few helpful extensions such IsAdministrator and IsBot methods which are used to check if the user belongs to those specific roles.
- TagContainerExtension: Contains few helpful extensions such as HasTags method that checks if the specified contain contains certain passed tags to this method or not. Tag Containers are stories and users.
Helpers
About Check & Argument classes:
Helpers contains developer helper classes such as Check & Argument. These classes are for developer support only and not intended to be exposed to public usage. You use these classes validate parameters passed to methods. Argument class is a nested class of Check. In future if there are addition things that belongs to Check other than arguments should be added as nested class inside Check.
- public class Check
- {
- internal Check(){}
-
- public class Argument
- {
- internal Argument(){}
- public static void IsNotEmpty(Guid argument, string argumentName)
- {
- if (argument == Guid.Empty)
- {
- throw new ArgumentException("\"{0}\" cannot be empty guid.".FormatWith(argumentName), argumentName);
- }
- }
- }
- }
Constants class:
Another helper common class, that supposed to hold all common constants used in all projects that form kigg solution. Currently it defines the CurrentCulture. It should also contains MaxDateTime, MinDateTime, CurrentVersion etc… Note that what is meant by constant not necessary be a constant type. for Example CurrentCulture return CultureInfo.CurrentCulture. So it is more like static shared information to all assemblies in this solution.
- public static class Constants
- {
- public static readonly DateTime ProductionDate = new DateTime(2008, 1, 11);
- public static CultureInfo CurrentCulture
- {
- get
- {
- return CultureInfo.CurrentCulture;
- }
- }
- }
SystemTime class:
Another form of constants but this time specific to Date & time.
- public static class SystemTime
- {
- public static Func<DateTime> Now = () => DateTime.UtcNow;
- }
PagedResult class:
This class is very important. It represents a single page in a results set. It also holds information about total records in the whole results that this page page is part of. Very useful for applying paging front end web pages such as displaying page of stories.
- public class PagedResult<T>
- {
- private readonly ReadOnlyCollection<T> _result;
- private readonly int _total;
-
- public PagedResult(IEnumerable<T> result, int total)
- {
- Check.Argument.IsNotNull(result, "result");
- Check.Argument.IsNotNegative(total, "total");
-
- _result = new ReadOnlyCollection<T>(new List<T>(result));
- _total = total;
- }
-
- public PagedResult() : this(new List<T>(), 0){}
-
- public ICollection<T> Result
- {
- get
- {
- return _result;
- }
- }
- public int Total
- {
- get
- {
- return _total;
- }
- }
- public bool IsEmpty
- {
- get
- {
- return _result.Count == 0;
- }
- }
- }
Configuration
KiGG provide many configuration parameters that can be supplied through configuration file. Or if you wish after knowing more about KiGG you can build these configuration to be stored and updated in database.
There is a special configuration settings interface that defines KiGG configurable system parameters such as number of stories to be displayed per page. For more details about different configuration settings I highly recommend that you read Overview of KiGG Configuration Settings in KiGG Deployment Guide Part 2.
IConfigurationSettings is the interface that defines those configurable parameters/properties of KiGG. This interface and its simple implementation declared under root namespace Kigg.
Conclusion
This part already get long enough. In this part I covered different namespaces defined in KiGG Core project. I also explored the root namespace “Kigg” with extensions, helpers and configuration classes defined on it. Covering the Core might take several parts itself.
In next part I’ll explore the infrastructure namespace under KiGG Core project. I hope enjoyed this part and found it informative.