ApplicationManager.cs - has anyone used this location for their datamappers?

R

Randy Smith

Hi ALL,
Our consultant added the datamapper definitions to our ApplicationManager.cs
file. Has anyone else used this technique, and how has it benefited you?
Here is what a sample of it looks like:

public static LaborRateDataMapper LaborRateDM;

static ApplicationManager()
{
LaborRateDM = new LaborRateDataMapper();
}

I've added 3 rows to my LaborRateTable, which appears via the
ApplicationManager datamapper. BUT, if I try to access these same rows
directly via LaborRateTable, the system is telling me that there are no
records.

Any ideas?

TIA, Randy Smith
 
K

Karl Seguin [MVP]

That's the only true way to achieve a lazy-loaded singleton in .NET. All
other methods will generally result in a [very very] slim possibility for
threading issues (As a matter of fact, the most used approach, double-locks
doesn't even work in Java, even though it's very widely used).

Given that it IS the correct implementation of a common design pattern, the
best we can do given the information provided is tell you that everything
looks ok. The question is whether you want LaborRateDataMapper instance
within your ApplicationManager to be a singleton -which is something no one
will be able to answer.

A couple notes though, there's a growing movement which feels that the
singleton is actually an anti-pattern. Also, static constructors introduce
a performance [very slight] performance penalty since any access to _any_
class members requires the CLR to check if the static constructor has
already been executed. FxCop will report this issue.

As for your problem, I can only guess that you have another instance of
LaborRateDataMapper somewhere. It would seem (although it's very hard to
tell), that the LaborRateDataMapper singleton should be implemented inside
the LaborRateDataMapper class, and not the ApplicationManager class -
although that's just a guess.

Karl
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top