Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Designing the business intelligence application

, 16 Jan 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
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 optimised 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.

/// <span class="code-SummaryComment"><summary>
</span>/// Entry point for the MvcApplication.
/// <span class="code-SummaryComment"></summary>
</span>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’.

/// <span class="code-SummaryComment"><summary>
</span>/// Initializes a new instance of the DashboardController class.
/// <span class="code-SummaryComment"></summary>
</span>/// <span class="code-SummaryComment"><param name="repository">parameter repository</param>
</span>/// <span class="code-SummaryComment"><param name="logger">parameter logger</param>
</span>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 authorisation providers to be implemented and is configured in the application's Web.config file.

A common authorisation 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.

@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 authorised 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

Authorisation 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.

/// <span class="code-SummaryComment"><summary>
</span>/// Controller class for Dashboard functionality.
/// <span class="code-SummaryComment"></summary>
</span>[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)

Share

About the Author

Mark Brownsword
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 PinmemberMark Brownsword17-Jan-11 15:19 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141216.1 | Last Updated 16 Jan 2011
Article Copyright 2011 by Mark Brownsword
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid