Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

Page: 1 2
# mgaerber 2/3/2006 1:21 AM (edited 2/3/2006 1:35 AM)
Since this doesn't quite fit into the modules discussion anymore (see modules, xsl module for previous posts) I am continuing here:

What I am about to do:
Create class "File" in Cuyahoga.Core.Domain
Create class "FileService" in Cuyahoga.Core.Service

FileService will handle common file operations.

Since CoreRepository is responsible for opening sessions (and much more at the moment), from my understanding, CoreRepository could be implemented as a "Composite", containing all other services (FileService, UserService etc.)

Or maybe CoreRepository could be sort of a Service Factory which finds a specific service by type and returns an initialized (provide session) service
to the requesters.

Something like: CoreRepository cr = ...

FileService fs = (FileService)cr.GetService(typeof(FileService));
File f = fs.GetFileById(...);
...

Of course, FileService would have to implement an interface allowing CoreRepository to initialize it.

Any ideas?


# mgaerber 2/3/2006 4:52 AM
Okay, this is what my solutions looks like so far:
	public interface IService
	{
		string Name { get; }
		void Initialize(ISession session);
	}
public class ServiceFactory
	{
		private static ServiceFactory serviceFactory = new ServiceFactory();

	
		protected ServiceFactory(){}

		public static ServiceFactory GetInstance()
		{
			return serviceFactory;
		}

		public IService GetServiceForType(System.Type type)
		{
			//is the requested type a service?
			if(null != type.GetInterface("IService", false))
			{
				//invoke default constructor
				ConstructorInfo ci = type.GetConstructor(new Type[0]);
				return (IService)ci.Invoke(new Type[0]);
			}
			else 
			{
				throw new Exception("The provided type does not implement IService");
			}
		}
	}

and in CoreRepository I added following method:
	public IService GetServiceForType(Type type)
		{
			IService s = this._serviceFactory.GetServiceForType(type);
			s.Initialize(this._activeSession);
			return s;
		}

Now, I am able to call an initialized service from a module like:
			CoreRepository cr = HttpContext.Current.Items["CoreRepository"];
			FileService fs = (FileService)cf.GetServiceForType(typeof(FileService));
# martijnb 2/3/2006 5:14 AM
You bring up a valid point here: The 'monolithic' CoreRepository (Service and Repository all in one) should be split up into decent services and repositories.

When looking at your code example I get a very strong feeling that the time is right to start looking at an IoC container like Castle or Spring.NET that manages the service creation. Perhaps with the NHibernate facility in Castle it can automagically hook everything up with a NH Session.
# leemhenson 2/3/2006 6:50 AM
I get a very strong feeling that the time is right to start looking at an IoC container like Castle or Spring.NET

Not that my opinion counts for much, but I second that motion!
# mgaerber 2/3/2006 8:24 AM
Alright, I didn't want to go that far and change too much code with this example.

And yes, an IoC would be the state of the art solution.
If you say IoC and Castle, you could use the full palette:

Castle.WindsorContainer (an extended Microkernel) with the
NHibernate facility, or even better, the ActiveRecord facility.

Sounds good to me.

# martijnb 2/3/2006 8:35 AM
mgaerberCastle.WindsorContainer (an extended Microkernel) with the
NHibernate facility, or even better, the ActiveRecord facility.

Could you motivate why we should use ActiveRecord?
# mgaerber 2/3/2006 8:53 AM (edited 2/3/2006 9:13 AM)
Hi,

following is "borrowed" from the ActiveRecord documentation:

# Fast development (it handles the mapping and infers as much as it can so you dont have to dig into documentation or deal with tons of xmls everytime something changes on your schema)
# Predefined common methods like Create, Update, Save, Delete
# Easy to implement method like Find, FindAll, FindByName...
# Session and transaction scopes that abstracts the ISession and translates them to a more natural idiom

Okay, this is still a matter of taste, because for me it feels like doubling effort, if I have to write an xml file saying the same thing as my class definition.

But other than that, the Castle project seems to be quite vivid and we could profit from the little extras as well, like the ActiveRecord Generator program, or strip out some of the scaffolding features from MonoRail, wich uses AR.

I'll have to find out, if the two facilities (NH and AR) are mutual exclusive, maybe both can live happily together...
and then everybody could use as much or as less extras as he wants

One addition:
If I wasn't able to choose (use both in a project) I would stick to plain NHibernate facility, because otherwise AR determines what you can do and what not.
# martijnb 2/3/2006 9:19 AM
mgaerberOkay, this is still a matter of taste, because for me it feels like doubling effort, if I have to write an xml file saying the same thing as my class definition.

You still have to write mapping attributes though, but like you said, it's a matter of taste. I just happen to like the xml file approach :).

But my main issue is that I don't think it will save that much time, at least not enough to justify being forced in a specific development style.
I'll have to find out, if the two facilities (NH and AR) are mutual exclusive, maybe both can live happily together...
and then everybody could use as much or as less extras as he wants

That wouldn't be problem, I guess. The whole point of Castle is that the facilities don't interfere.
# mgaerber 2/3/2006 10:07 AM
Alright, you're the architect ;-)
I'll have a closer look into NHibernate facility.

Just to summarize, the approach would then involve:

1.)
Factor out services from CoreRepository, which will then be accessible using WindsorContainer.
2.)
Add NHibernate facility
3.)
Rewrite modules to benefit from new architecture

As anything else on the wishlist would probably be affected by these changes, how could we help?

# big_al 2/5/2006 1:02 AM
Why not just use MyGeneration to generate the NHibernate xml and include the MyGen project in the cuyahoga source?

It's a free tool and save a whole lot of time and will save having to create another set of interfaces to map attributes ;)
# mgaerber 2/5/2006 9:12 AM
Don't know about that but what would *really* be great is, if we could generate sql statements for newly written domain classes for all those nice db's that Cuyahoga supports or will support.

I know MyGeneration has this database analyzing stuff integrated, do you know if this could be accomplished?
# martijnb 2/5/2006 10:12 AM
mgaerberDon't know about that but what would *really* be great is, if we could generate sql statements for newly written domain classes for all those nice db's that Cuyahoga supports or will support.

NHibernate already has such a feature. It's called SchemaExport. Too bad it only works for initial creation. SchemaUpdate exists but only for the Java version.

Now about MyGeneration: I'm aware of what it can do but there is one fundamental problem and that is that the model is DB-driven so you lose many opportunities to do some proper OO design.
# big_al 2/6/2006 1:24 PM
martijnbNow about MyGeneration: I'm aware of what it can do but there is one fundamental problem and that is that the model is DB-driven so you lose many opportunities to do some proper OO design.

I was thinking more about using MyGen. to create the schema, not the domain model.

Though you can edit the templates to your hearts content so it wouldn't be impossible to have a template to suite your model.

You could also create templates to create the base classes for Cuyahoga classes / modules, such as whats available for DNN.

Creating a template set for such things in MyGeneration could also provide Cuyahoga with some extra exposure ;)
# mgaerber 2/7/2006 3:29 AM (edited 2/7/2006 3:31 AM)
Thinking pragmatically, the mapping files contain (almost) all information to generate both, the (plain) Domain Classes and the DDL.

Thinking OO, packages and classes are my primary point of interest.

So for me, the ideal process looks like:

1. Design the model (VS 2005 class designer or UML Tool)

2. Add some NHibernate specific meta attributes

3. Generate classes, mapping files and ddl.

Since NHibernate can generate ddl based on mapping files, the question is, what could we use to convert the model to mapping files?



# martijnb 2/7/2006 1:17 PM
Thinking pragmatically, I think the tools that should help us here aren't good enough yet. MyGeneration doesn't fit (maybe to generate module skeletons) and the NHibernate hbm2ddl and hbm2net tools don't look too good either.

But it isn't in fact that much of an issue, because coding the NHibernate stuff by hand doesn't take long and there aren't zillions of classes involved.

The area where we need a tool is the database schema management. I don't know how many of you maintain scripts for three different databases by hand, but I can tell you that's not very funny!
I've tried dozens of CASE-like tools but they were either too expensive or just couldn't do the job.
# mgaerber 2/7/2006 11:59 PM
martijnb the NHibernate hbm2ddl and hbm2net tools don't look too good either.
...
The area where we need a tool is the database schema management.

Okay, I didn't get to use the NHibernate tools yet.
Could they be a basis for setting something on top, or should we be looking more for are specialized db-diff tool?
# martijnb 2/8/2006 2:12 PM
mgaerberOkay, I didn't get to use the NHibernate tools yet.
Could they be a basis for setting something on top, or should we be looking more for are specialized db-diff tool?

Don't bother looking. I've searched the entire web and beyond and there was nothing that suited. I just hope that one day, NHibernate gets a fully working SchemaUpdate tool.

Maybe we should just all move to RoR where schema updates are part of the package :).
# martijnb 2/8/2006 2:17 PM
Btw, at the moment, I'm starting to get into the entire IoC thing and a need a little bit more study time to get all the pieces of the puzzle together.
Any of you guys know the Alfresco framework (for Java, at alfresco.org)? It's a great source for inspiration. At least it made me understand more about how to identify the services etc.
# mgaerber 2/9/2006 12:52 AM (edited 2/9/2006 1:09 AM)
Not until now...

They're basing the whole thing on JSR-170. Sadly, Microsoft is still due to commit itself to something compatible or another architecture.

Are you thinking about going the JSR-170 way, or are you just looking at the spring way of IoC?

Its always great to be standards-aware, the only question is if this is beyond the scope of what we can achieve?

Digging more into it, I found these introductory articles:

http://www-128.ibm.com/developerworks/java/library/j-jcr/
http://incubator.apache.org/jackrabbit/faq.html

and here is a powerpoint presentation on JSR-170
http://www.oscom.org/events/oscom4/proposals/jsr170.html
# martijnb 2/9/2006 2:05 AM
No, I'm not looking for a JSR spec or something. Just trying to see how others deal with IoC.
Page: 1 2