Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / C#

Designing the Business Intelligence Application

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
16 Jan 2011CPOL4 min read 18K   10   1
Designing the business intelligence application

A well designed application provides a foundation of infrastructural services that can be leveraged by developers. This article takes a look at building the skeleton of a business intelligence application with ASP.NET MVC 3. ASP.NET MVC is Microsoft’s acknowledgement that enterprise technologies can embrace the stateless and open web. The MVC architecture is best suited to applications that have testability, extensibility and maintainability in mind, i.e., applications that will grow and be around for a while.

The first point to notice about an MVC application is that the navigation URI maps to a method (Logon) on the controller (Account) e.g. http://AdventureWorks/Account/LogOn. There is no need to specify the page name and note that MVC will not allow direct navigation to pages. This provides a separation of concerns where the controller accepts the request, orchestrates the retrieval of data and then determines how to return this data to the client browser.

The data source for a business intelligence application will typically come from some kind of data warehouse where the table structure has been optimized for reporting and analysis. Separate endpoints may exist, for e.g., reporting, analysis and dashboard forming a hub & spoke model. A separate project in our business intelligence application will represent this domain model and a service will be made available for developers to request data in a form that can be manipulated using LINQ queries.

Before diving into the use of infrastructural services, some housekeeping. The start of a new project is a great time to make a resolution to bring StyleCop into the development process. StyleCop provides a mechanism for enforcing consistency in coding practices, e.g., placement of variables, constructors, properties, private and public members, layout of coding constructs and source code commenting appear consistent in every file.

NuGet is a new package management component added to Visual Studio 2010. Check out the video on the website for an introduction. NuGet can be activated in Visual Studio 2010 by right clicking on the References node in Solution Explorer and selecting ‘Add Library Package Reference’. NuGet allows third part libraries (and dependencies) to be included into an application and takes care of adding references, etc.

The key concept for leveraging infrastructural services in this business intelligence application is Dependency Injection. Dependency Injection provides the mechanism to decouple service implementations from their abstract interface in a way that makes it possible to ‘swap’ services with minimal impact on the working application, e.g., many large websites running on server farms will have experienced the frustration of needing to update configuration settings accessed through .NET’s built in ConfigurationManager. The draining and resetting of individual servers in the farm can take some time. A configuration service implemented using Dependency Injection allows for a change to a custom implementation that picks up setting changes on the fly to occur by building a new configuration service. Its use throughout the application remains unchanged.

ASP.NET MVC 3 has improved its support for Dependency Injection to the point where there is no barrier to its use. There are many third party Dependency Injection containers to choose from. For this business intelligence application, I will use Microsoft’s Unity. The Patterns and Practices team have done a great job of documenting the how and why of dependency injection with Unity. The following code shows how to initialise Unity in the Global.asax Application_Start method. Services for Membership, Repository and Logging are registered with Unity and these can be requested throughout the application.

C#
/// <summary>
/// Entry point for the MvcApplication.
/// </summary>
protected void Application_Start()
{
    AreaRegistration.RegisterAllAreas();

    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);

    // Initialise the Unity container.
    var resolver = new UnityDependencyResolver();

    resolver.Container.RegisterType<IMembershipRepository, MembershipRepository>(
        new ContainerControlledLifetimeManager());
    resolver.Container.RegisterType<IWarehouseRepository, WarehouseRepository>(
        new ContainerControlledLifetimeManager());
    resolver.Container.RegisterType(
        typeof(IAdventureWorksLogger<>),
        typeof(Log4NetLogger<>));

    // Set Unity as the Dependency Resolver.
    DependencyResolver.SetResolver(resolver);
}

When the business intelligence application runs, Unity will be used to construct controllers and will automatically provide references for the Repository and Logger services. This is ‘constructor injection’.

C#
/// <summary>
/// Initializes a new instance of the DashboardController class.
/// </summary>
/// <param name="repository">parameter repository</param>
/// <param name="logger">parameter logger</param>
public DashboardController(
    IWarehouseRepository repository,
    IAdventureWorksLogger<DashboardController> logger)
{
    this.repository = repository;
    this.logger = logger;
}

Other services used by the business intelligence application are based on the provider model from ASP.NET, e.g., Membership & RoleManager. Since MVC functionality sits on top of classic ASP.NET, these capabilities are still available. This allows for custom authentication and authorization providers to be implemented and is configured in the application's Web.config file.

A common authorization scenario to handle is the user that has logged on to the application but then attempts to navigate (by directly typing the URL into the browsers' address bar) to a page that they don’t have permission to view, e.g., a business user may navigate directly to a page that is intended only for the site administrator. The code below shows the Logon page and the new Razor view engine syntax with MVC’s ability to output HTML based on conditions.

ASP.NET
@model AdventureWorks.BusinessIntelligence.Web.Models.LogOnModel
@{ ViewBag.Title = Model.Title;
   Layout = Url.Content("~/Views/Shared/AccountLayout.cshtml"); }

@if (Request.IsAuthenticated)
{
    // if the user is authenticated, but not authorized to see
    // the requested page, then show a message requesting
    // valid credentials.
    <p>Please enter valid credentials for the requested page</p>
}
else
{
    <p>Enter your account details to logon, or register for a
        new account</p>
}

Logon

Authorization occurs based on attributes added to controller classes, with failures being directed to the Account controllers Logon method. This is configured in the Web.config authentication section.

C#
/// <summary>
/// Controller class for Dashboard functionality.
/// </summary>
[Authorize(Roles = Constants.Membership.BusinessUser)]
public class DashboardController : Controller {…}

This article has explored the delivery of infrastructural services through dependency injection and classic ASP.NET provider models. These services provide the foundation of an extensible and maintainable application design. The source code for the business intelligence application is available on my SkyDrive (requires Visual Studio 2010 with MVC 3). The next step in evolving this application will be to display the AdventureWorks Call Centre data in a dashboard and introduce client side interactivity with Ajax.

CodeProject

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Australia Australia
I've been working as a software developer since 2000 and hold a Bachelor of Business degree from The Open Polytechnic of New Zealand. Computers are for people and I aim to build applications for people that they would want to use.

Comments and Discussions

 
GeneralCode Download Pin
Mark Brownsword17-Jan-11 14:19
Mark Brownsword17-Jan-11 14:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.