Wednesday 8 July 2015

Bibliography OF spring.net

Spring.net developers in India


SR NO
Web References
1
http://springframework.net/
2
3
4
www.tutorialspoint.com/spring/spring_dependency_injection.htm
5
martinfowler.com/articles/injection.html
6
http://tutorials.jenkov.com/dependency-injection/index.html
7
http://stackoverflow.com/questions/130794/what-is-dependency-injection
8
www.javatpoint.com/spring-aop-tutorial
9
www.tutorialspoint.com/spring/aop_with_spring.htm
10
hibernate.org/orm/what-is-an-orm/
11
http://sourceforge.net/projects/springnet/
12
sourceforge.net/projects/nhibernate/

http://www.ifourtechnolab.com/application-development.aspx


Tuesday 7 July 2015

Spring.NET - Conclusion

Spring.net developers in India

At last using Spring.Net Software development companies can create decouple application which is useful for enterprise level. Spring.Net effectively uses dependency injection which is use for linking module at runtime. Thus it is used to make everything independent. AOP also use for keeping things separate from core logic so that we can keep core implementation and testing for QA separate for use.

Practical usage of spring.net

Spring.net developers in India

  • Now to deal with data, Spring.NET provides NHibernate and ADO.NET support. 
  • To NHibernate handles all things about database and work in the object world only.
  • Now download Spring.Net source and find bin folder and load Spring.Core, Spring.Web,Spring,Spring.Data,Spring.Data.NHibernate12 and NHibernate from lib folder.

Let us take an example and understand the complete process. For hibernate i defined a table in the database named employee, create a new class named Employee and a NHibernate mapping file (Employee.hbm.xml). Reference: Custom software development company:

Employee Class

using System;
namespaceMyProject.DAO
{
public class Employee : ICodeEntity
{
private long idno;
private string fname;
privateint age;
//These methods should be virtual for NHibernate Mapping
public virtual long Id
{
get { return idno; }
set { idno = value; }
}
public virtual int Age
{
get { return age; }
set { age = value; }
}

public virtual string FName
{
get { return fname; }
set { fname = value; }
}
}
}
Employee.hbm.xml
<?xmlversion="1.0"encoding="utf-8" ?>
<hibernate-mappingxmlns="urn:nhibernate-mapping-2.2"namespace="MyProject.DAO"assembly="MyProject.DAO">
<classname="Employee"table="tblemp">
<idname="Id">
<columnname="ID"not-null="true"/>
<generatorclass="increment" />
</id>
<versioncolumn="Age"name="Age" />
<propertyname="FName">
<columnname="FirstName"length="20"not-null="true" />
</property>
</class>
</hibernate-mapping>

Now using base class implements basic functionality of database like LoadALL,SaveOrUpdateetc. Define an Interface and implement.

using System;
usingSystem.Collections.Generic;
usingSystem.Collections;

namespaceMyProject.DAO
{
publicinterfaceIMainDAO<EntityT, idT>
{
IListGetAll();
EntityTGetByID(idT id);
IListLoad(stringhsqlQuery, object[] values);
void Save(EntityT fine);
voidSaveOrUpdate(EntityT fine);
NHibernate.ISessionFactorySessionFactory{ set; }
}
}

Implementation of interface

MainDAO
using System;
usingSystem.Collections.Generic;
usingSystem.Text;
usingSpring.Data.NHibernate;
usingNHibernate;
usingSystem.Collections;
namespaceMyProject.DAO
{
publicabstractclassMainDAO<EntityT, idT> : IMainDAO<EntityT, idT>
{
protectedHibernateTemplatehibernateTemplate;

publicISessionFactorySessionFactory
{
set
{
hibernateTemplate = newHibernateTemplate(value);
hibernateTemplate.TemplateFlushMode = TemplateFlushMode.Auto;
}
}
publicMainDAO()
{
}
publicvirtualEntityTGetByID(idT id)
{
EntityT entity = (EntityT)hibernateTemplate.Load(typeof(EntityT), id);
return entity;
}
publicvirtualIListGetAll()
{
returnhibernateTemplate.LoadAll(typeof(EntityT));
}
publicvirtualIList Load(stringhsqlQuery, object[] values)
{
returnhibernateTemplate.Find(hsqlQuery, values);
}
publicvirtualvoid Save(EntityT fine)
{
ICodeEntity entity = (ICodeEntity)fine;
hibernateTemplate.Save(fine);
}
publicvirtualvoidSaveOrUpdate(EntityT fine)
{
ICodeEntity entity = (ICodeEntity)fine;
hibernateTemplate.SaveOrUpdate(fine);
}
}
}

By Adding a new property to Default.aspx code file named EmployeeDAO we have to use the interface of DAO class here.


Default.aspx code

using System;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
usingMyProject.DAO;
publicpartialclass_Default : System.Web.UI.Page
{
privatestringmsg;
publicstringMsg
{
get { returnmsg; }
set { msg = value; }
}
privateMathmathx;
publicMathMaths
{
get { returnmathx; }
set { mathx = value; }
}
IEmpDAOempDAO;
publicIEmpDAO EMPDAO
{
get { returnempDAO; }
set { empDAO = value; }
}

protectedvoidPage_Load(object sender, EventArgs e)
{
Response.Write(msg);
Response.Write(mathx.add(10, 20));
Employee e1 = newEmployee();
e1.FName = "Martin Parmar";
EMPDAO.Save(e1);
Employee e416 = EMPDAO.GetByID(1); 
}
}

Now configuration of hibernate in web.xml file

<?xmlversion="1.0"?>
<configuration>
<configSections>
<!-- Spring -->
<sectionGroupname="spring">
<sectionname="context"type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
<sectionname="objects"type="Spring.Context.Support.DefaultSectionHandler, Spring.Core"/>
<sectionname="parsers"type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core"/>
</sectionGroup>
</configSections>
<!-- Spring -->
<spring>
<parsers>
<parsertype="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data"/>
</parsers>
<context>
<resourceuri="config://spring/objects"/>
</context>
<objectsxmlns="http://www.springframework.net"xmlns:db="http://www.springframework.net/database">
<!-- You may choose any database -->
<!--<db:provider id="DbProvider" provider="SqlServer-1.1" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=F:\projects\pm\App_Data\PM9Database.mdf;Integrated Security=True;User Instance=True"/>
<db:provider id="DbProvider" provider="SqlServer-1.1" connectionString="Data Source=.\SQLEXPRESS;"/>-->
<db:providerid="DbProviderMySQL"provider="MySql"connectionString="Server=localhost;Database=persondb;User ID=root;Password='';"providername="MySql.Data.MySqlClient"/>
<objecttype="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
<propertyname="ConfigSections"value="databaseSettings"/>
</object>
<objectid="SessionFactory"type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12">
<!-- Depending on database you want set it-->
<propertyname="DbProvider"ref="DbProviderMySQL"/>
<propertyname="MappingAssemblies">
<list>
<value>MyProject.DAO</value>
</list>
</property>
<propertyname="HibernateProperties">
<dictionary>
<entrykey="hibernate.connection.provider"value="NHibernate.Connection.DriverConnectionProvider"/>
<entrykey="hibernate.dialect"value="NHibernate.Dialect.MySQLDialect"/>
<entrykey="hibernate.connection.driver_class"value="NHibernate.Driver.MySqlDataDriver"/>
</dictionary>
</property>
</object>
<!--TxManager-->
<objectid="HibernateTransactionManager"type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate12">
<propertyname="DbProvider"ref="DbProviderMySQL"/>
<propertyname="SessionFactory"ref="SessionFactory"/>
</object>
<objectname="MyMathObj"type="Math, App_code"/>
<objectid="EmployeeDAO"type="MyProject.DAO.EmployeeDAO, MyProject.DAO">
<propertyname="SessionFactory"ref="SessionFactory"/>
</object>
<objectid="EmployeeDAOTx"type="Spring.Transaction.Interceptor.TransactionProxyFactoryObject, Spring.Data">
<propertyname="PlatformTransactionManager"ref="HibernateTransactionManager"/>
<propertyname="Target"ref="EmployeeDAO"/>
<propertyname="TransactionAttributes">
<name-values>
<addkey="Save*"value="PROPAGATION_REQUIRES_NEW"/>
<addkey="SaveO*"value="PROPAGATION_REQUIRES_NEW"/>
<addkey="Delete*"value="PROPAGATION_REQUIRED"/>
<addkey="Update*"value="PROPAGATION_REQUIRED"/>
<addkey="Query*"value="PROPAGATION_REQUIRED"/>
</name-values>
</property>
</object>
<!-- Pages -->
<objecttype="Default.aspx">
<propertyname="Msg"value="Hello!!! I am from webconfig"/>
<propertyname="Maths"ref="MathObj"/>
<propertyname="EmployeeDAO"ref="EmployeeDAOTx"/>
</object>
</objects>
</spring>
<appSettings/>
<connectionStrings/>
<system.web>
<compilationdebug="true">
<assemblies>
<addassembly="System.Transactions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
<addassembly="System.Configuration.Install, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation>
<authenticationmode="Windows"/>
<httpHandlers>
<!-- Spring Handler -->
<addverb="*"path="*.aspx"type="Spring.Web.Support.PageHandlerFactory, Spring.Web"/>
<addverb="*"path="*.asmx"type="Spring.Web.Services.WebServiceHandlerFactory, Spring.Web"/>
</httpHandlers>
<httpModules>
<addname="SpringModule"type="Spring.Context.Support.WebSupportModule, Spring.Web"/>
<!-- Required for managing NHibernate session between http requests-->
<addname="OpenSessionInView"type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate12"/>
</httpModules>
</system.web>
</configuration>

Above source code sample is from a custom software development company.

Sunday 5 July 2015

Object Relational Mapping in Spring.Net

Spring.net developers in India
Object relation mapping is one king of method that relates real world object to data source as described by software development companies. There are certain issues to map object to data source but ORM provides three ways to deal it like bottom up, top-down and meet in the middle. Each approach has its own advantage and disadvantage. To select the best software solution, developers have to understand the environment and design requirementscompletly. 

There are certain benefits of ORM:
  • Simplified development because ORM automates object-to- data table and data table-to-object conversion, resulting in lower development and maintenance costs
  • Code is reduce as compare to other database like stored procedure. 
  • Improve performance by keeping transparent caching in application.
  • By creating optimum solution, it makes application faster.

Custom software development companies should consider following object relational mapping tools which are used in .Net
·         Base One Foundation Component Library, free or commercial
·         Castle ActiveRecord, ActiveRecord for .NET, open source
·         DatabaseObjects .NET, open source
·         DataBloks .NET, free or commercial
·         DataObjects.NET, commercial
·         Dapper, open source
·         ECO, commercial but free use for up to 12 classes
·         Entity Framework, included in .NET Framework 3.5 SP1 and above
·         EntitySpaces, was commercial, now free
·         iBATIS, free open source, maintained by ASF but now inactive.
·         LINQ to SQL, included in .NET Framework 3.5
·         LLBLGen Pro, commercial
·         Neo, open source but now inactive.
·         nHydrate, open source
·         Persistor.NET, free or commercial
·         Quick Objects, free or commercial
·         Signum Framework, open source
·         SubSonic, open source


Friday 3 July 2015

Transaction management in Spring.net

Spring.net developers in India

Transaction management in Spring.net provides following main benefits as custom software development companies :
  • Provides a straightforward API for programming model such as ADO.NET, Enterprise Services and System. Transactions, and NHibernate.
  • Provide declarative transaction management using any of the data access technologies
  • Provides API which is very easy to use and applicable on programmatic transaction management
  • Integrates with high level persistence integration APIs such as AdoTemplate.

Cosider following interface which is defined by transaction. It is called
Spring.Transaction.IPlatformTransactionManager interface, shown below:

public interface IPlatformTransactionManager {
ITransactionStatusGetTransaction(ITransactionDefinition definition );
void Commit( ITransactionStatustransactionStatus );
void Rollback( ITransactionStatustransactionStatus );
}

IPlatformTransactionManager is an interface and its implementations can be defined by any other object in the IoC container. Consider following implementations:

  • AdoPlatformTransactionManager: Transaction based on local ADO.NET
  • ServiceDomainPlatformTransactionManager: like distributed transaction manager from Enterprise Services
  • TxScopePlatformTransactionManager:It is local/distributed transaction manager which belongs toSystem.Transactions.
  • HibernatePlatformTransactionManager:It is local transaction manager which is use with NHibernate or ADO.NET/NHibernate data access operations.


The following API are made. For the AdoPlatformTransactionManager,

Transaction.Begin(), Commit(), Rollback(). ServiceDomainPlatformTransactionManager uses the'Services without Components' update so that your objects do not need to inherit fromServicedComponent or directly call the Enterprise Services API ServiceDomain.Enter(), Leave;ContextUtil.SetAbort()TxScopePlatformTransactionManager calls; new TransactionScope(); .Complete(),Dispose(), Transaction.Current.Rollback(). Configuration properties for each transaction manager are specific tothe data access technology used. Refer to the API docs for comprehensive information but the examples shouldgive you a good basis for getting started. The HibernatePlatformTransactionManager is described more in thefollowing section.

The GetTransaction(..) method returns a ITransactionStatus object and it is depending on aITransactionDefinition parameters. The returned ITransactionStatus may represent a new or existingtransaction (if there was a matching transaction in the current call stack - with the implication being that ITransactionStatus is associated with a logical thread of execution.

The ITransactionDefinition interface is described by software development companies as follow:

  • Isolation: the degree of isolation means the transaction is reading data of another transaction. So if another transaction leave in uncommitted phase then current transaction has data which is not exist.
  • Propagation: Most of code executed within a transaction boundary will run in that transaction‘s scope. However, there are several possible options there to specify behavior if a transactional method is executed when a transaction context already exists like, simply continue running in the existing transaction or suspending the execution of existing transaction and creating another new transaction.
  • Timeout: Amount of time taken by transaction before timeout. It is automatically being rolled back by the underlying transaction infrastructure.
  • Read-only status: Any data cannot be modified by a read-only transaction. This type of transaction is very much useful for optimization purpose in some area (Especially while using NHibernate).





Monday 22 June 2015

Dependency Injection in Spring.Net

Spring.net developers in India

Dependency Injection is a technique that provides decoupling application from the actual implementation during design/compile time and link them at run time. 

When we consume a class instance like ClassB from another class instance ClassA at compile time, then any changes which going to be made to ClassB will affect ClassA. For any single change, we need to recompile, redeploy the whole thing. Here, there is a static or compile time binding between ClassA and ClassB. Dependency Injection is one of the techniques that relieves us from the pain of static binding and decouples ClassA and ClassB at runtime. The end result, a decoupled or loosely coupled system.

Let’s consider an application being developed by software development companies which contains three layer Presentation Layer (UI), Business Login (BAL) Layer and Data Access Layer (DAL).  In that UI interacts with BAL and BAL interact with DAL. In tightly coupled system, UI is depended on BAL and BAL is depended on DAL so problem is that if make any changes in DAL then it is required to compile or redeploy rest of the layer. Where in case of loosely coupled system any instance can be changed at runtime rather than compile time. So by enforcing DI in application development we can link the layer at runtime, we can also develop layer independently and integrate later.  

Advantage of Using DI:

  • Consider following for DI, whichcan be used in a real time:
  • The dependent layer can be changed at runtime based on the environment.  
  • The rapidly bug fixes can be done offline and linked at integration/testing phase 
  • Side by side development of different layers which can be linked at integration phase.

Creating loosely typed System Using Dependency Injection

At first, create layered architecture in which there are Presentation, Business login and Data Access layer. UI interacts with Business Login and Business Login further interact with Data Access layer to get data.

Here by adding dependency injection in layered architecture, we can get change any instance at runtime rather than at compile time so there will not any dependency among all layers. Moreover, we are going to link layer at runtime.

Steps to implement DI in DotNet:

  1. At first, it is required to create Interfacefor all layers, especially interface for Business login and Data access layer which contain method definition.
  2. Give implementation of interface by both layers, BAL and DAL respectively.
  3. Perform Spring configuration in dotnet in configuration file in which create unique instant for all above layer so that they can serve multiple request.
  4. Add reference for Spring.Core in application and initialize your configuration by ContextRegistry.GetContext() method which validates about existence of your objects that you have created in configuration file and this method will return IApplicationContext instance
  5. Now once instance is initialized then you can call method of DAL from BAL instance.

Real time use:

  • Runtime change the dependent layer like create two kind of environment one for production which contains actual implementation and another for testing environment.
  • Parallel development of layer and final can be integrated or linked.
  • decoupling application from the actual implementation during design/compile time and link them at run time is the prime use of dependency injection for custom software development companies


Tuesday 16 June 2015

Overview of Spring.NET

Spring.net developers in India

Spring.Net is open source framework which is used to develop enterprise level light-weight application to custom software development companies. The design of Spring.Net is based on the Java Spring Framework. Spring.Net provides following:

  • Dependency Injection
  • Integrate Aspect-Oriented Programming in application.
  • Transaction management for middle tier.

Spring.Net is application at so many area. Core features, such as the Dependency Injection, AOP and the data access framework can be used in pretty much any .NET application. They allow you to create simple and pure applications. 
Spring.Net consists of following main modules:

  • Spring.Core: Configure your application using DI
  • Spring.Aop: Provides various libraries for transactions, logging, performance monitoring, caching and exception handling.
  • Spring.Data: Support data access facilities with ADO.NET.
  • Spring.Data.NHibernate: Integrating hibernate with transaction management and provides object relational mapping.
  • Spring.Services: This includes dotnetremoting,web services using DI. 
  • Spring.Web: Provides level of abstraction with ASP.NET web application.
  • Spring.Web.Mvc3/4/5: Integrates Spring.Core and Spring.Aop into Dotnet MVC.

Spring.Net also support WCF integration which provides dependency Injection and application of AOP to WCF service.
It is not compulsory that custom software development companies have to use all the above module or not anything. It just likes creating ASP.NET front-end and write business logic using IOC and interact with middle layer which supports various services like transaction management along with accessing data.

Monday 15 June 2015

What is Spring.net?

Spring.net developers in India

Spring.Net is application framework which helps to develop enterprise .NET applications to asp.net software development companies. The main important features of spring.net is Dependency Injection (DI) or Inversion of Control (IC) and AOP framework which is very useful and completely platform independent. In this report I am going to present advantages of loosely coupled system over tightly coupled system and also create loosely coupled by inserting dependency injection. Sometimes in complex system it is difficult to link modules or layered at runtime means each layered are depended, like UI interacts with business login (BAL) and further BAL interacts with data access layer (DAL) so if we made any changes to DAL then we have to make change to respective layer too. So I have shown implementation by using dotnet framework and spring.net library and create MVP kind of layer architecture.

Keywords: DI, AOP, BAL (Business Access Layer), DAL (Data Access layer).

Objectives

  • Main objective to use Spring.net is its one of features like Dependency Injection which simplifies coupling related issues and provide loosely couple code.
  • Reduce tight coupling among different software components.
  • Easily manage future changes and complexity.
  • Another objective to achieve AOP- aspect-oriented programming which increase modularity by separation of code.

Software development companies can use SPRING.NET for the development of enterprise applications to make them robust, reliable and safe.