views:

51

answers:

4

Hello Everyone,

I have a quick question that I am hoping is fairly simple to answer. I am attempting to develop a shared Employee object library for my company. The idea is to create a centralized database that contains information about our employees (Reporting Hierarchy, Office Locations, General Info, etc) and then create an shared object library for this database.

My question is what is the best way to create this library so it can be shared among applications.

  • Do I create a self contained library that stores the database connection (I can see concurrency issues here and it doesn't feel right).
  • Client -> Server and then deploy the "client library" for use among any application.
  • OR would a Web/WCF service be more ideally suited to this situation.
+1  A: 

I usually prefer to have a middle tier layer (so some sort of Web/WCF service between the client and the database). This way you separate the clients from the database, so that you can control the number of connections, or you can change the schema of the database in a way that will be transparent for the clients.

Depending on your situation, you can either make the clients connect to the WCF service (preferred in most cases), or create a dll that will wrap the connection to the service and perform some additional processing on the client side.

Grzenio
+1  A: 

It depends how deep you need to integrate you library into main application. If you want to extend application domain with custom entities, you have following options:

  • Built-in persistence into library. You will need to pass connection string to repository class, but also database must include the hardcoded scheme for your library. If you use LINQ to SQL as data access library, you may mark up you entities with mapping attributes (see http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.aspx)
  • Provide domain library only, but implement persistence outside, if your data layer supports POCO mapping (EF 4 do).

Usually, putting domain model into separated assembly causes few problems:

  • Integration into application. Application itself usually provides few services, like data access, security, logging, web services etc. If your application have ideal design and layers fully decoupled from each other, there is no problem to add new entities, but usually data access layer requires inheritance from base class, logger is singleton, security checks are hardcoded into business logic methods etc. Such applications must be refactored, services must be extracted into interfaces, and such interfaces must be passed to components in separated assembly.

  • Entity references. If you use rich domain model, you probably want to reference entities declared in another assembly . Partially this problem can be solved by generics, but you need to have special design of your data access layer that allows you to get lists of generic entities, or get entity by id etc.

  • Database integration. It may be hard to maintain database changes, if some entities are developed separately from others, espesially by other team.

STO
A: 

Just be sure to keep your connection method separate from your data access layer, and then you can change the connection method later if requirements change. If you have a simple DLL that holds your real logic, then adding a communication layer on top should be simple. This will also allow you to use all three methods you mentioned and have all your actual logic in a single DLL used amongst all three.

highphilosopher
+1  A: 

There are many options because the question can be translated broadly. I suggest taking to heart all answers. Having said that here's my spin on it...

I used to view software layers as vertical because of n-tier training, and have a hard time breaking away from those notions to something conceptually broader and less restrictive. I strive to view .NET assembles as just pieces of a puzzle.

You're right to separate connection string from code and that's easily supported by .NET .config file, or application settings.

I often prefer a small, core library having the business logic, concepts and flows although each of those can be broken out. And within that concept you can still break out business from data access as different assemblies to swap in a new kind of data access. But sticking with the core module (a kind of "business kernel" or "engine" if you will).

You can express your "business kernel" through many presentation types, for example

  • textual/Console I-O
  • GUI: WinForms, WPF, Silverlight, ASP.NET, LED/pixelboard, etc
  • as cmdlets for Powershell interactions
  • web service expressions
  • kinds of mobile apps
  • etc.

You can accelerate development using patterns to bend software to your will and related implementations like: Microsoft Enterprise Library, loosen the coupling with dependency injection e.g. Ninject (one of many), or inversion of control techniques, etc.

John K