Knowledge is power. We love to share it.

News related to Mono products, services and latest developments in our community.

khorvat

MonoX Architecture Explained - the API Layer

07/31/2013Categories: MonoX

I have described the MonoX UI in one of my previous articles on MonoX architecture. In this article I’ll try to explain all aspects of MonoX API and how to get the best out of it, but before we start it would be great if you go over Part 1 to get a better overview of the MonoX architecture.

This is a Part 2 of the “MonoX Architecture Explained” series. 

API Layer

Being a large Web application that reaches out to a rather wide audience, MonoX exposes a few API layers that you can use. Let’s start with core API layers and move on to high-level functionality that you will be using the most.

Please note that on-line version of MonoX API is available, so you can always look up a specific feature there, or submit a support ticket when in doubt.

Data Access Layer (DAL)

DAL is a low-level layer that is used by MonoX to communicate with the database. It is generated by the LLBLGen ORM tool, so before you dig into it, you might want to get familiar with the LLBLGen API. LLBLGen is a very powerful and mature tool with a great community, so you can also use their forums to get help on more advanced database related functionality.

The most important architectural decision we made was to use the LLBLGen Adapter Template group, which implements the IDataAccessAdapter to communicate with the database. I’ll explain how to get to the IDataAccessAdapter in the next section, and now let’s stick to the DAL. The source code of the latest versions of MonoX DAL are available publicly in our GitHub repository, so you can extend the DAL layer acording to your needs. You can take a look at the screenshots below that show the DAL folder structure you will be working with. We have two projects here - one for database specific classes such as data access adapter bound to your database (LLBLGen supports multiple database technologies) and another, database generic project which contains all the entity classes and utilities that you will be using. The DatabaseGeneric project contains all strongly typed fields and classes that you need to use in order to build your custom filters, entity classes that perform CRUD operations, etc. The good thing here is that all the entity classes are partial, so you can always extend them by adding another partial class and inserting your custom code into it. If you are about to extend MonoX’s data model with your own tables, you will have to obtain a license for LLBLGen designer application to add/map tables and re-generate new entities. We tried to make your job easier by providing full source code for the DAL project.

 

imageimage

 

Repository Layer

This is where most of the fun begins and ends: repository layer is the one responsible for fetching and shaping the data from database via previously described DAL. To get the IDataAccessAdapter associated with LocalSqlServer connection string - which is used to do all the communication with the database - you need to call GetAdapter() on MonoX’s BaseMonoXRepository (in MonoX v5.0 this would be a call to DependencyInjectionFactory.Resolve<IGenericRepository>().GetAdapter() but more about the MonoX v5.0 API in one of my upcoming articles). Below is a list of the repositories that MonoX has available for you to extend. You can directly inherit from one of them and override anything you need to change, including filtering and sorting. Let say a few words about each of them:

  • AdRepository.cs  - this repository is used by campaign & ad management module inside MonoX
  • AlbumRepository.cs- this repository is used for managing MonoX Photos & Albums in Photo gallery module
  • BlogRepository.cs- this repository is used for managing MonoX Blogs
  • CalendarEventRepository.cs- this repository is used for working with MonoX Calendar schedule
  • CommentRepository.cs- this repository is used for managing MonoX comments used by various modules - blogs, forums, etc.
  • DiscussionRepository.cs- this repository is used for working with MonoX discussion boards
  • DocumentRepository.cs- this repository is used for working with MonoX documents (HTML Editor documents)
  • EventRepository.cs- this repository is used for managing MonoX Social Activity Stream
  • FileRepository.cs- this repository is used for managing files uploaded by members. It is related to the MonoX File System engine and providers but we will discuss this topic in detail in my next article MonoX Architecture Explained - the Core
  • FriendRepository.cs- this repository is used for managing social relations
  • GroupRepository.cs- this repository is used for working with MonoX groups and uses NoteRepository, DiscussionRepository, FileRepository & AlbumRepository
  • ListRepository.cs- this repository is used for working with simple lists module
  • LocalizationRepository.cs- this repository is used by MonoX resource providers - Database Resource provider in virtually all scenarios
  • MembershipRepository.cs- this repository is used for managing member accounts beside the use of ASP.NET Membership providers
  • MessageRepository.cs- this repository is used by InMail messaging modules
  • NavigationRepository.cs- this repository is used for managing MonoX menu navigation
  • NewsletterRepository.cs- this repository is used for managing MonoX newsletters
  • NewsRepository.cs- this repository is used by MonoX News administrations and News modules
  • NoteRepository.cs- this repository is used by the "social" Wall module
  • OauthTokenRepository.cs- this repository is used by Open Social API which will be explained in the following section
  • PageRepository.cs- this repository is used for managing MonoX Pages and their settings
  • PollRepository.cs- this repository is used by the Poll module
  • RatingRepository.cs- this repository is used for managing content ratings site-wide
  • RelationshipRepository.cs- this repository is used by almost every MonoX repository and module. It is important to understand how MonoX data model is designed to allow various customizations. In order to connect your custom functionality e.g. Products with MonoX Comments you only need to add new SnEntityType entry, inherit the RelationshipRepository, override all the methods and add Products handling. I won’t go into the details and provide a source code samples here, we will dedicate a whole article to that subject.
  • SubscribeRepository.cs- this repository is used by subscription providers for managing subscriptions to various entities from MonoX e.g. Blog posts, Discussion Boards & Topics, etc.
  • UserProfileRepository.cs- this repository is used for managing user profiles. You will probably need to extend this repository in order to extend the user profile and add custom fields to it. 
  • UserRepository.cs- this repository is used for managing MonoX users, you can consider this repository as a built-in extension of the MembershipRepository

Business Logic Layer (BLL)

If you are not familiar with the Business Logic Layer pattern please read the following article that explains that subject in detail. MonoX BLL is used as a middle spplicstion layer, between the MonoX UI and Repository Layer. It is the right place for handling tasks such as data access security checks, custom business-specific logic, data access caching, etc. Below is a list of available BLLs in MonoX; I won’t go into details for each of them, as you may note that almost all Repositories are paired with appropriate BLLs.

CalendarEventBLL.cs
ConfirmationBLL.cs
DiscussionBLL.cs
GroupBLL.cs
NavigationBLL.cs
NewsBLL.cs
OAuthTokenManagerBLL.cs
PageBLL.cs
RatingBLL.cs
RelatedContentBLL.cs
SubscribeEngineBLL.cs
UserProfileBLL.cs

MonoX API (a.k.a Simple API)

If you are feeling overwhelmed with the material I layed out above, than Simple API may be the right choice for you. We have tried to package small, but usable, subset of MonoX’s functionality and expose it in a simple way. Hre is what you can do with the Simple API:

  • Manage MonoX Users & Roles
  • Manage MonoX Photo Albums
  • Manage MonoX Activity Stream
  • Manage MonoX Groups

If you are interested in this API Layer please read more about it here.

OpenSocial API

OpenSocial is a great feature that is supported by many Web services. “With OpenSocial, it's easy to have your app reach users where they get work done; in their activity stream, in content, in email, or even on their mobile device.” MonoX features a full support for OpenSocial - if you are not familiar with it you can read more here. We have already covered this topic in an earlier article, so I would suggest it as a definitive resource.

MetaWebLog API

MetaWebLog is an application programming interface that enables CRUD operations in your blog. More information can be found in Wikipedia or in this nice blog post. We have described the MetaWebLog support for MonoX via Windows Live Writer in this blog post. It is a fairly simple API and I won’t go into more details here, but if you have any questions please feel free to contact our support team.

MonoX Utilities & MonoSoftware Framework

Have you ever caught yourself reinventing a wheel ? Well I have and you probably did too, so it is always a good thing to know what tools you have at your disposal. MonoX has a rich set of utility classes that you can use in your work, let me list a few important utilities that can help you a lot :

  • MonoSoftware.MonoX.SecurityUtility – contains a lot of easy to use security-related methods such as GetUserId, GetUserName, IsAdmin etc.
  • MonoSoftware.MonoX.RewritenPaths – a set of strongly typed url rewrite rules, T4 template is included so you can regenerate the class
  • MonoSoftware.MonoX.UrlParams – an utility class used to access the query parameters in a strongly typed way
  • MonoSoftware.MonoX.Paths – a set of strongly-typed virtual paths - T4 template included. This script will collect all of your solution files and make them accessible through strongl -typed properties
  • MonoSoftware.MonoX.Utility.UrlUtility – a set of methods that will help you parse, rewrite and manipulate URLs
  • MonoSoftware.MonoX.Utility.LocalizationUtility – will allow you to check the current language of the requested page, get other languages and will help you rewrite the links to be localized
  • MonoSoftware.MonoX.Utility.LogUtility – will help you log your debug information or errors
  • MonoSoftware.MonoX.Utility.MonoXUtility – a set of many utility methods like binding helpers, MonoX rendering engine helpers, etc.
  • MonoSoftware.Core namespace – contains various classes that can help you serialize objects, encrypt data, convert or generate various types, etc.
  • MonoSoftware.Web namespace – contains various Web-related classes like URL helpers, formatters, antispam providers, caching helpers, data transfer managers (DataManager) similar to AutoMapper etc.
  • MonoSoftware.LLBLGen namespace – contains base classes for MonoX repositories and many more utility classes related to LLBLGen
  • To find out more about the MonoX API please visit the official API page here.

 

Summary

As you can see, MonoX introduces a rich API built on top of various technologies and third party APIs, so I hope there is something for everyone.  If you like the layered application architecture you can user MonoX BLLs & Repositories. If you like it simple then you will probably want to use MonoX Simple API, and if you need to have a distributed application you can use the OpenSocial API as an end point. At the end, if you just need to manipulate the blog section, MetaWebLog API might be the right choice for you. In the end, it is always good to keep in mind that there are multiple means to implement the same target functionality.

Rated 3.67, 3 vote(s). 
link to the next article (for "The Core") is broken
"LLBLGen Adapter Template" group link is broken
khorvat
Thanks, we will correct the links.