Spring.Net Presentation - Chris Donnan : Programming ...

bricklayerbelchedInternet and Web Development

Feb 5, 2013 (4 years and 9 months ago)

138 views

Copyright © 2005 Finetix LLC

All Rights Reserved



0

SpringFramework.Net Developer Session

Chris Donnan

The Peer Frameworks Series
-

.Net and Java


Copyright © 2005 Finetix LLC

All Rights Reserved



1

SpringFramework.net 50,000 Ft View

Core

AOP

Services

Data Access

Web

Desktop

Windows Services


3
rd

Party
Integration

Copyright © 2005 Finetix LLC

All Rights Reserved



2

Application Context

“One Singleton to rule them all”

The IApplicationContext is the ‘normal’ top level entry point to use

SpringFramework.net


Inside you will find (along with other stuff) implementation of:



IObjectFactory


IResourceLocator


These are the interfaces that are most used in day to day programming

With Spring.

Copyright © 2005 Finetix LLC

All Rights Reserved



3

Spring ObjectFactory


The center of it all…



Since the Application Context is an IObjectFactory


you can use it

To act as a ‘dynamic factory’ for your objects.


You simply ask the factory for your object


and you use it as you normally

Would use any “new’d” object.


The real beauty is that Spring manages assembling that object for you


Giving it whatever dependencies it needs.

Copyright © 2005 Finetix LLC

All Rights Reserved



4

Spring Resource Abstractions

You can also use the IApplicationContext’s IResourceLocator interface:

This allows you to get your resources from wherever they may be. This could

Be at a URL, a File, an Embedded Resource, etc.

Copyright © 2005 Finetix LLC

All Rights Reserved



5

Spring.net Demo


DEMO.


Building a complex business object with many dependencies


Prototypes and singletons


Populating collections

Copyright © 2005 Finetix LLC

All Rights Reserved



6

Aspect Oriented Programming


Cross Cutting functionality


Logging


Transactions


Security


Other code that tend to repeat across an application

Copyright © 2005 Finetix LLC

All Rights Reserved



7

AOP

Basic code


nothing special

Copyright © 2005 Finetix LLC

All Rights Reserved



8

AOP

Copyright © 2005 Finetix LLC

All Rights Reserved



9

AOP

Code to invoke programmatically

Output from execution

Copyright © 2005 Finetix LLC

All Rights Reserved



10

AOP XML Conifguration

Same as programmatic usage


XML Configuration

Copyright © 2005 Finetix LLC

All Rights Reserved



11

AOP

Copyright © 2005 Finetix LLC

All Rights Reserved



12

Spring Web


Bidirectional data binding


Via attributes



Master Pages in .Net 1x



Dependency Injection for ASP.NET pages/ web services



Result Mapping



MVC Framework for ASP.Net



Copyright © 2005 Finetix LLC

All Rights Reserved



13

Data Binding

public class UserRegistration : Spring.Web.UI.Page

{


[Binding("Text", "UserInfo.Email")]


protected TextBox email;



[Binding("Text", "UserInfo.Address.PostalCode")]


protected TextBox postalCode;



…….

}


*Notice it uses Expression synatax

Copyright © 2005 Finetix LLC

All Rights Reserved



14

Result Mapping

Used to externalize the mapping of action results to target pages:


<object id="homePageResult" type="Spring.Web.Support.Result,
Spring.Web">


<property name="TargetPage" value="~/Default.aspx"/>


<property name="Mode" value="Transfer"/>


<property name="Parameters">


<dictionary>



<entry key="literal" value="My Text"/>



<entry key="name" value="${UserInfo.FullName}"/>



<entry key="host" value="${Request.UserHostName}"/>


</dictionary>


</property>

</object>

Copyright © 2005 Finetix LLC

All Rights Reserved



15

Spring Data Access and Transactions


ADO.Net



Hibernate



IBatis.net



Basic patterns and utility classes/ base classes to speed up creating
DAO and templated data access classes.



Transaction support



The goal is to reduce code needed to get rolling!

Copyright © 2005 Finetix LLC

All Rights Reserved



16

Hibernate Code Examples



public class NHTestObjectDao : HibernateDaoSupport, ITestObjectDao

{


[Transaction()]


public void Create(TestObject to)


{


HibernateTemplate.Save(to);


}

}

Copyright © 2005 Finetix LLC

All Rights Reserved



17

Hibernate Config Example

<object id="DbProvider"


type="Spring.Data.Support.SqlProvider, Spring.Data">




<property name="ConnectionString"


value="Data Source=(local);Database=Spring;User
ID=springqa;Password=springqa;Trusted_Connection=False"/>


</object>


<object id="SessionFactory"


type="Spring.NHibernate.LocalSessionFactoryObject, Spring.NHibernate">



<property name="DbProvider" ref="DbProvider"/>


<property name="MappingAssemblies">


<list>


<value>Spring.NHibernate.Integration.Tests</value>


</list>


</property>


<property name="HibernateProperties">


<dictionary>






</dictionary>


</property>

</object>

Copyright © 2005 Finetix LLC

All Rights Reserved



18

Spring Expressions

Evaluation of text expressions against live objects. Sort of like XPath for
objects.


Simple Example:


Inventor tesla =
new

Inventor("Nikola Tesla",
new

DateTime(1856, 7, 9), "Serbian");


tesla.PlaceOfBirth.City = "Smiljan";
string

evaluatedName = (
string
)
ExpressionEvaluator.GetValue(tesla, "Name");


string evaluatedCity = (
string
) ExpressionEvaluator.GetValue(tesla, "PlaceOfBirth.City"));

Copyright © 2005 Finetix LLC

All Rights Reserved



19

Expressions Continued

This can get more complex. You can evaluate objects sub parts, sub parts, etc.



Inventor pupin = (Inventor) ExpressionEvaluator.GetValue(ieee, "Officers['president']";


string

city = (
string
) ExpressionEvaluator.GetValue(ieee,
"Officers['president'].PlaceOfBirth.City");


ExpressionEvaluator.SetValue(ieee, "Officers['advisors'][0].PlaceOfBirth.Country",
"Croatia");


In the latest Spring.net release
-

there is support of literals, logic, properties,
indexers, arrays, types, and lots more

Copyright © 2005 Finetix LLC

All Rights Reserved



20

SpringFramework.net DAF


Desktop Application Framework



Pub/ Sub like events


UI Application Container


Injection of dependencies into Controls/ Forms


Model/ View/ Controller | Presenter infrastructure


UI Services Model (ways to GET UI services in a consistent way)


Toolbars


Docking Managers


Status Bars
-

etc


Databind binding framework


Grid Binding


Expression based simple binding


Object Views (alternative to attributes)


Expression based validation

Copyright © 2005 Finetix LLC

All Rights Reserved



21

The Peer Frameworks Series
-

.Net and Java




1)
Spring Framework Developer Session
-

SpringFramework.net,
SpringFramework.org

2)
Test Drive Development Developer Session

-

NUnit, JUnit;
Rhino Mocks in .net and Easy Mock in Java

3)
Db4o Developer Session

-

Open Source Object Database in .net
and Java

4)
ORM Developer Session

-

Hibernate, NHibernate / IBatis

Copyright © 2005 Finetix LLC

All Rights Reserved



22

Ruby does IoC

Concrete Implementations