Cricinfo Live Scores

Tuesday, June 3, 2008

Spring .NET 3 Tier Application Architecture


1. Introduction
This document will help to kick start the design of SPRIG .NET based applications. In this document we will describe about prototype application architecture and all details about the architecture.
2. Application Architecture
A common 3-tier application will be discussed in this document.
· UI
· Facade
· BO
· DAO
· NHibernate
· SQL Server 2005
2.1 UI
Here UI is implemented in ASP .NET 2.0. Very common design


We do have a list of names and from the list when one will be selected then its detail will be displayed in the side. Next, we can change and update information. We can delete a selected one and if we need we can add a new one to the list too.
2.2 Facade
Facade of this application is the gateway to the buisness part. For example we have the following code
using System;
using System.Collections;
using System.Text;
using Entity;
using BO;

namespace Common
{
public class Facade
{
private IssueBO m_IssueBO;

public IssueBO IssueBO
{
get { return m_IssueBO; }
set { m_IssueBO = value; }
}

public IList AllIssue()
{
return IssueBO.AllIssue();
}

public Issue IssueById(long lIssueId)
{

return IssueBO.IssueById(lIssueId);
}

public void SaveIssue(Issue oIssue)
{
IssueBO.SaveIssue(oIssue);
}

public void UpdateIssue(Issue oIssue)
{
IssueBO.UpdateIssue(oIssue);
}

public void DeleteIssue(long lIssueId)
{
IssueBO.DeleteIssue(lIssueId);
}

}
}

Here IssueBO is our buisness object. If we want to disable a service from the solution we can just comment it from the Facade class.
2.3 BO
Our buisness part is something like this
using System;
using System.Collections;
using System.Text;
using Entity;
using DAO;

namespace BO
{
public class IssueBO
{

private IIssueDAO m_IssueDAO;

public IIssueDAO IssueDAO
{
get { return m_IssueDAO; }
set { m_IssueDAO = value; }
}


public IList AllIssue()
{
return (IList)IssueDAO.LoadAll();
}

public Issue IssueById(long lIssueId)
{

return IssueDAO.LoadByID(lIssueId);
}

public void SaveIssue(Issue oIssue)
{
IssueDAO.Save(oIssue);
}

public void UpdateIssue(Issue oIssue)
{

IssueDAO.Update(oIssue,oIssue.Id);
}

public void DeleteIssue(long lIssueId)
{
IssueDAO.Delete(lIssueId);
}
}
}

We do have an Interface object which contains the DAO object for this buisness class.
2.4 DAO
Here One IBaseDAO interface is created which is a Generic solution.
using System;
using System.Collections.Generic;
using System.Collections;

namespace DAO
{
public interface IBaseDAO
{
IList LoadAll();
EntityT LoadByID(idT id);
IList Load(string hsqlQuery, object[] values);
void Save(EntityT fine);
void Update(EntityT fine, idT id);
void Delete(idT id);
NHibernate.ISessionFactory SessionFactory { set; }
}
}

An abstract BaseDAO implements the IBaseDAO interface generically.
using System;
using System.Collections.Generic;
using System.Text;
using Spring.Data.NHibernate;
using NHibernate;
using System.Collections;
using Entity;

namespace DAO
{
public abstract class BaseDAO : IBaseDAO
{
protected HibernateTemplate hibernateTemplate;

public BaseDAO()
{
}

public ISessionFactory SessionFactory
{
set
{
hibernateTemplate = new HibernateTemplate(value);
hibernateTemplate.TemplateFlushMode = TemplateFlushMode.Auto;
}
}

public virtual EntityT LoadByID(idT id)
{
EntityT entity = (EntityT)hibernateTemplate.Load(typeof(EntityT), id);
hibernateTemplate.Evict(entity);
hibernateTemplate.Flush();
return entity;
}

public virtual IList LoadAll()
{
return hibernateTemplate.LoadAll(typeof(EntityT));
}

public virtual IList Load(string hsqlQuery, object[] values)
{
return hibernateTemplate.Find(hsqlQuery, values);
}

public virtual void Save(EntityT fine)
{
IEntity entity = (IEntity)fine;
hibernateTemplate.Save(entity);
hibernateTemplate.Flush();
}

public virtual void Update(EntityT fine, idT id)
{
EntityT entity = (EntityT)hibernateTemplate.Load(typeof(EntityT), id );
hibernateTemplate.Evict(entity);
hibernateTemplate.Flush();
hibernateTemplate.Update((IEntity)fine);
hibernateTemplate.Flush();
}


public virtual void Delete(idT id)
{
EntityT entity = (EntityT)hibernateTemplate.Load(typeof(EntityT), id);
hibernateTemplate.Evict(entity);
hibernateTemplate.Flush();
hibernateTemplate.Delete(entity);
hibernateTemplate.Flush();
}

}
}

And following is a DAO which has an IIssueDAO interface to maintain constraints. IssueDAO implements the interface and extends the BaseDAO class.

using System;
using System.Collections.Generic;
using System.Text;
using Entity;

namespace DAO
{
public interface IIssueDAO : IBaseDAO
{
}

public class IssueDAO : BaseDAO, IIssueDAO
{
}

}

2.5 Nhibernate
Here is the issue.hbm.xml file.

namespace="Entity" assembly="Entity">
























Here is the Issue Entity


using System;
using System.Collections.Generic;
using System.Text;

namespace Entity
{
public class Issue:IEntity
{
private string m_Name;
private string m_Description;
private bool m_IsActive;
private long m_Id;

//These methods should be virtual for NHibernate Mapping

public virtual long Id
{
get { return m_Id; }
set { m_Id = value; }
}

public virtual string Name
{
get { return m_Name; }
set { m_Name = value; }
}

public virtual string Description
{
get { return m_Description; }
set { m_Description = value; }
}

public virtual bool IsActive
{
get { return m_IsActive; }
set { m_IsActive = value; }
}

}

}
Issue.hbm.xml and Issue Entity mapped to give the serive of ORM for Issue Table in the databse.

2.6 Sql Server 2005
Here is the Issue Table information for the database.


3. Spring .NET
Spring .NET is implemented using change in the web.config file. The structure of the file is maintained in this way.

Here in the spring folder there is
Aspects.xml, Bo.xml, Dao.xml, Facade.xml, Services.xml, Transaction.xml, Web.xml and web.config holds the total thing together.
Web.config file selects the above xml as its object context.
Projects contain the following library files too


3.1 Web.config
When aspx request comes from the browser to the application deployed server. Then it will be dispatched the spring.web part.

Then, aspx file will inject dependecy for its page. Next facade will inject dependency, next BO will inject dependency and set transaction manager for the DAO object.
3.2 Web.xml
Each aspx file will have the Facade Property. And all the service required for the web page will he given throgh the facade class.


Here is the content of spring/web.xml file. The Dependecy injection for the aspx page will be added.


3.3 Facade.xml
Here all those BO of the facade class will injected. And, facade is managed as singleton here. So that it can be treated as class service.


3.4 BO.xml
Here for a BO class there is a DAO property and it will have the Transaction object IssueDAOTx. It is the built in service for transaction management of spring .net application.


3.5 DAO.xml
Here is the DAO xml for the spring .net application. Here hmb files and the entity classes will be mapped. Hibernate properties and session factory is created here. Changing the database server is managed here. If we want to change the Database server from MSSQL to (Oracle, MySQL etc) then we need to change the dialect and the driver. And, we should have the database provider dll for the Nhibernate. Here we have used Spring.data.Nhibernate12.dll.


3.6 Transaction.xml
It contains all the transaction settings for the DAO classes.

3.7 Aspects.xml, Services.xml
Aspects will be used for incorporating customized AOP to the application. Services will contain the xml configuration for the web service part of the application.
4. Result

Output of the total solution architecture yields

:):):)::::::::::) I will try to improve my writing later


Change the Default Location of the My Documents Folder

Change the Default Location of the My Documents Folder

To change the default location of the My Documents folder, follow these steps:
1.Click Start, and then point to My Documents.
2.Right-click My Documents, and then click Properties.
3.Click the Target tab.
4.In the Target box, do one of the following:
Type the path to the folder location that you want, and then click OK. For example, D:\My Stuff.

If the folder does not exist, the Create Message dialog box is displayed. Click Yes to create the folder, and then click OK.

-or-
Click Move, click the folder in which to store your documents, and then click OK twice.

If you need to create a new folder, click Make New Folder. Type a name for the folder, and then click OK twice.
5.In the Move Documents box, click Yes to move your documents to the new location, or click No to leave your documents in the original location.