.net - Use Singleton Pattern For LINQ To SQL Persistence?

Apr 16, 2011

I have a table, Users, with a related child table, UserSecurityGroups. In my GUI, the operator would select a user from a list. The program would retrieve the user record and allow the operator to edit the user data in one form. The operator could also edit the UserSecurityGroups of this user on another form.

I am considering using a singleton class for user instance retrieval and persistance back to the database. If this is a good practice, I want to use this with many other tables in my DB. My question is: Is this a good practice? What pitfalls am I missing? What would you recommend as an alternative? Would your recommendation change since I also have tables with three or four levels of relations (as opposed to two in the example above)?

Here is my proposed code:

Imports System.Data.Linq
Public Class UserConduit
Implements IDisposable

[code]....

View 1 Replies


ADVERTISEMENT

Singleton Pattern In Vb?

Jul 23, 2010

I am normally a c# programmer but am now working in VB for this one project when I use to set up a singleton class I would follow the Jon Skeet model

public sealed class Singleton
{
static Singleton instance = null;
static readonly object padlock = new object();

[code]....

I get StackTracker.Instance.Instance and it keeps going, while it is not the end of the world it looks bad.is there a way in VB to hide the second instance so the user can not recursively call Instance?

View 1 Replies

How To Singleton Pattern Using Interfaces?

Jul 5, 2010

I am working on creating a customized UI composite control. This control would be a container to several other custom controls.As a first step, i am creating the container UI using a singleton pattern. This is because at any point in time only one isntance of this container is allowed to be created. This is fine.Now i want to practice interface based desgin. So i introduced a sinple interface calleD IdesignSurface which has two properties. I would like my singleton class to implement this interface,so i tried something like this and got an error saying "end of line

NotInheritable
Class DesignSurface
implements IDesignSurface

[code]......

View 2 Replies

Implement The Singleton Pattern?

Oct 16, 2009

Im trying to Implement the Singleton Pattern and im wondering if this is "Thread Safe" or if I am going to have to explicitly perform a SyncLock on the object instance? Example:

Public NotInheritable Class SingleTon
Private Shared _singleton As SingleTon
Private Sub New()

[Code].....

I tried it both ways, using the SyncLock and without, just not sure which one to be using?

View 18 Replies

Implement The Singleton Pattern For Access Via WCF?

Aug 17, 2010

I'd like to expose some functionality via a WCF service. I can configure WCF to instantiate a class per-request but am unsure how I can get a reference to a communal singleton if I were to have some functionality to store a list of calls to a method (call it LogMethod) via WCF in memory and return that list when the GetLogs method is called

I'm aware I could use a database/the file system to pass this data back an forth but in many cases, that seems to be overkill. Edit: It seems that nobody has a clear answer - I can't believe this is complex. Am I missing something obvious?

View 2 Replies

VS 2008 Singleton Factory Implementation - Is Pattern Implementation Right

Mar 18, 2010

So I've been doing some research on the singleton factory design pattern, and I am wondering if my example implementation is correct (warning I did get carried away creating animals):

[Code]...

View 6 Replies

Gradually Transition To NHibernate Persistence Logic From Existing ADO.NET Persistence Logic?

Sep 3, 2010

The application uses ADO.NET to invoke sprocs for nearly every database operation. Some of these sprocs also contain a fair amount of domain logic. The data access logic for each domain entity resides in the domain class itself. ie, there is no decoupling between domain logic and data access logic. I'm looking to accomplish the following:

[Code]...

View 2 Replies

MessageBox Persistence In .net?

May 30, 2011

I'm using MessageBox to give some information to the user, but when such a box pops up, I want it to block access to the main window. So, until the user has clicked "OK", they should not be able to click (or even focus on) the window that's below it.

Does anybody know how to do this? I've noticed that MessageBox has very few functions, so maybe I'll even have to use a different object for this.

View 3 Replies

ASP.NET Server Data Persistence?

May 28, 2010

I'm not really sure exactly how the question should be phrased, so please be patient if I ask the wrong thing.I'm writing an ASP.NET application using VB as the code behind language. I have a data access class that connects to the DB to run the query (parameterized, of course), and another class to perform the validation tasks - I access this class from my aspx page.What I would like is to be able to store the data server side and wait for the user to choose from a few options based on the validity of the data. But unless my understanding is completely off, having persistent data objects on the server will give problems when multiple users connect?

My ultimate goal is that once the data has been validated the end user can't modify it. Currently I'm validating the data, but I still have to retrieve it from the web form AFTER the user says OK, which obviously leaves open the possibility of injecting bad data either accidentally (unlikely) or on purpose (also unlikely for the use, but I'd prefer not to take the chance).So am I completely off in my understanding? If so, can someone point me to a resource that provides some instructions on keeping persistent data on the server, or provide instruction?

Concrete Example: We recently hired Inspector Gadget to insert data for the Sign Inspectors who go 'round inspecting the highway signs to make sure none of them have been mangled or stolen by bubble-gum chewing, normally upstanding members of the youth city council.If Gadget can prove his mettle then he might get promoted to do the actual sign inspections. For now, his only job consists of going to this intranet site an inputing information about the most recent inspections. The district, county, route #, section of road, and dates the sign was installed and inspected.

Of course any of us who were alive in the late 80's are familiar with Gadgets ineptitude. So the site is about as Gadget proof as we can make it. The district/county/route is all filled out through a dropdown list, he only has to manually enter the section start and end and the dates. On occasion he fumbles the mouse and ends out swapping the begin and end of the section, doh! So the text turns red to alert him of the mistake. Unfortunately he chose to wear his anti-red sunglasses today that turn all red colors to black. Well, after attempting to submit the data it shows him an error message telling him where and what he needs to fix. Unfortunately he fat fingered the keyboard and instead of inputting 1.337 he put in 13.37 (miles)- and the road is only 10 miles long! Well, now a message (a modal div) pops up and tells him that the real mileage for the road is 0-10, and that his entry will combine three sections of the road. Then he is given three buttons to choose from. Cancel, which allows him to go and modify his data, Constrain, which will convert 13.37 to 10, and Override which will allow him to input that data anyway.

"Yowza!" Gadget exclaimed, and clicked cancel to go back and fix his mistake. Well the next set of data he input correctly, so a confirmation message popped up showing him the changes he was about to make and asking if it was OK to continue. Well, unfortunately Inspector Gadget knocked over his coffee cup, scattering detritus across his desk. In his haste to clean it up, he clicked "OK", but not before his Go-Go-Gadget electro-magnet accidentally flipped a few bits on his computer, changing the county in the form from ARKANSAS to AKRSANAS, doh!

Had the data been stored on the server across campus, and the only information passed was "OK" or "Cancel", this would have been avoided.Of course I can always validate again after the "OK", but it just seems like a hacky workaround.

View 2 Replies

.net - Persistence Of User Scoped Settings?

Jan 22, 2012

I have a Boolean, user scoped setting. I access it through a referenced class library, called Settings. This class library has a Module with properties:

[Code]...

While the code is running this works. But after a restart of the application the new value is not persisted.

View 2 Replies

Custom Control Property Persistence During Runtime

Aug 30, 2011

How to get a property to persist after its been changed dynamically during run-time? When Visual Basic reverts back to the IDE, the property goes right back to its original value.

View 3 Replies

.net - How To Initialize A Singleton

Nov 6, 2009

Sometimes there is a need to initialize the singleton class with some helper values. But we can't "publish" a constructor for it. What is the workaround for this?overloading the GetInstance or setting a color is not my idea. The color should be set only once. I would like to be sure that MyPainter paints ONLY with the initialized color. Any default color should ever be used.

For more clarity I provide a sample:

''' <summary>
''' Singleton class MyPainter
''' </summary>
Public Class MyPainter

[code]....

View 5 Replies

VS 2008 Mdi App Singleton?

Jan 19, 2010

I have recently discovered the singleton approach to mdi child forms and I was trying to integrate this singleton stuff into my "mChildform" class but I keep getting InvalidTypeCastException when I do so. Not sure where I am messing this up.

My mChildform class inherits Form and adds a few properties that are required by all child forms. All of my other project forms inherit this mChildform as their base type instead of form.

When I go directly to one of these forms (the logs form for example) and add

[code...]

I get the exact results that I want. Naturally, since this is something I want all child forms to be able to do I try to add it to my mChildform base class.

The code compiles, but since the reference is of mChildForm type I want to cast it to my usable form class, but it throws the InvalidCastException.

[code..]

I'm not sure why I can't cast it to the other form type, but i'm hoping someone here can explain why I cannot. The Instance() check would always fail if I do not cast my instance to another one of the types.

Since my mChildForm class only holds minimal info to do any real work I have to cast it to the other type. As a workaround I can add the instance method to each new form but I would really like to get it into the base class.

View 5 Replies

Generator For Singleton Code

Jan 26, 2009

In the Designer of my forms I usually have this for Singleton purposes.[code]Is there any hack in the IDE that would let me just press a button or something and it will automatically add the code I have above to the selected Designer?I can always type or copy/paste/modify it but I thought there could be something that I could set to just automate this redundant task.

View 7 Replies

Is The Singleton In ASP.NET Per Session Or Per Machine

Sep 8, 2010

I have an web application written in ASP.NET (FW 3.5) (along with some VBScript, this is a legacy app) that uses a utility class in the backend that logs error. I need to log several values that a user has entered in the front-end. Since the utility class has no access to the front end (or any HTTP services), i created a singleton class within the utility namespace that my front end UI can access and store information about the user.

I guess more specifically, I am wondering if there's a way to store session variables that can be shared across the web application and web services through a class referenced by both of the application and web services. For example, I have an error handling class that is used by both instances that required information about the user. Is there a way to create a per-session singleton to hold that information, so that my error class will have access to the user info?

View 1 Replies

Singleton Class In Webapplication?

Jun 11, 2009

Reading about singletons classes/pattern gave me a pretty good idea for its use. But would it be a good practice to store user related variables in properties of a thread safe singleton class so i can access them by chaining?

Example
When a user logs in several variables will be assigned to a session variable like:
Session("UserID") = reader("UserID")
Session("AccessLevels") = reader("Accesslevels")
Session("UserName") = reader("UserName")
...

Now when working on my webapplication i could always access these values by calling the session() variable, but the chance to forget the session keys or erroneous write them down is significantly. So again would it be good to store these session variables in readonly properties of singleton class so I can access them like:

MySingleton.ID
MySingleton.Accesslevels
MySingleton.UserName

View 4 Replies

.net - Singleton Initialized Multiple Times

Jun 27, 2012

So I took this from an example. GetInstance() is called from hundred different places in my program, and when I debug, the line "Prog = New Program" keeps getting hit for each of those calls. Which I thought was exactly what should NOT happen.. Or do I have some fundamental misunderstanding?

[Code]....

It seems the "New" sub triggers a number of calls to Program.GetInstance, before the first one completes. This is due to me earlier having lots of shared public objects in this class, which are no longer shared since the class was made singleton. And these objects, when initialized, calls the Program class for reference to other of it's objects.

View 2 Replies

Cross-AppDomain Singleton With Remoting ?

Mar 8, 2011

I have an Addin for MS Excel which needs a singleton to share data amongst modules.Depending on the version of Excel (2003, 2007, 2010), and how Excel was started, it calls my addin from different, unpredictable AppDomains, which prevents the classic singleton approach.Creating a custom AppDomainManager won't work because Excel has already created the AppDomains before the addin is called.

Linking to mscoree to enumerate domains breaks the addin registration process (and I really don't want that anyway); there doesn't seem to be any other way of enumerating, so that isn't an option either.The only solution that I've found is to use remoting. Here's my test rig:

Imports System.Runtime.Remoting
Imports System.Runtime.Remoting.Channels
' Remeber to add reference to System.Runtime.Remoting DLL[code].....

Once everything is running, access to the singleton takes ~100µS, which is perfect. I can live with the ~400mS the first time each AppDomain is initialised. The problem is at startup, where the remoting invocation takes ~2.5 seconds.

View 1 Replies

Explain Singleton Architecture Of Remoting?

Jun 6, 2011

Explain Singleton architecture of Remoting.

View 1 Replies

Implement Singleton In Parent Class?

Nov 18, 2009

Implement singleton in a parent class.Infact what I want is that All the childs etc. should use same instance of the parent.

I have implemented singleton, Changed the scope of parent class's constructor to "Protected". But in the application when ever the new child's constructor is called i.e. "Dim abc as New Ch1()" the constructor of Parent is called (as it is Proctected and can be access from child).

View 2 Replies

Implementing Singleton In Parent Class?

Nov 18, 2009

implement singleton in a parent class. Infact what I want is that All the childs etc. should use same instance of the parent.

I have implemented singleton, Changed the scope of parent class's constructor to "Protected". But in the application when ever the new child's constructor is called i.e. "Dim abc as New Ch1()" the constructor of Parent is called (as it is Proctected and can be access from child). Which is undesired behaviour.

View 2 Replies

Multiple Instances Of DCOM Singleton

May 19, 2011

Testing a configuration of a Windows 7 workstation acting as a "server" and a Windows XP workstation acting as a "client" (also fails in the same way using a Windows 7 client workstation).

[Code]...

View 8 Replies

Add Persistence To Multiple DataGridView In Terms Of Hide/Show Column And Column Width

Feb 24, 2010

Add persistence to multible DataGridView in terms of Hide/Show column and column width

View 1 Replies

Singleton Classes And Interfaces : Unable To Get The Results

May 10, 2012

I am trying to create an interface and then about 3 or 4 singleton classes that would be accessed via the interface.I know how to get interfaces to work and I know how to create concrete singleton classes and access them via GetInstance(). But when I put the two together, failure results.My problem is in the GetInstance method of the concrete singletons as in

Public Class MovingList
implements ISelectedList

[code]....

ISelectedList is the interface. This fails because ISelectedList.GetInstance is not of the type MovingList. Plus there is a problem with the use of Shared that I think is solved by simply deleting it (interfaces implicitly share).I can't define the type of ISelectedList.GetInstance because each of my singleton classes is of a different type even though they implement exactly the same properties and methods.How best to implement such singleton classes? I could do away with the interface and simply deal directly with the concrete singletons but that feels like bad practice. Programming to an abstraction not an implementation and all that.

View 6 Replies

.net - Can't Call Serialize() On Instance Of Serializable Singleton Class?

Nov 28, 2011

I have a VB.NET singleton class which implements Serializable:

Imports System.IO
Imports System.Runtime.Serialization

<Serializable()> Public Class CoordinateHistory[code].....

My problem is that I can't actually call .Serialize() on the instance of this class, like all of the examples online show. What am I doing wrong?

View 2 Replies

Singleton Class Or Shared (static) Member Functions?

Aug 9, 2011

I would like to understand the Pro & Cons in using the commonly used methods via Singleton class against Shared (Static) members of a class in VB.Net. It could be in terms Time, Space complexity or best practices. I have a BankAccount class with methods doing some business logic.

GetBalance()
GetLast5Credits()
GetMiniStatement()

[code].....

View 4 Replies

Multi Web Services So Multi Singleton

May 14, 2011

i have one project with multiples web services so i created various singleton class thinking in

performance. now i think create one singleton class and that have the instances of my webservices

[code...]

View 1 Replies

.net - ActiveRecord Linq/NHibernate Linq Not Building Query Completely?

Jul 14, 2011

given this function:

Public Function Search(ByVal StartIndex As Integer, _
ByVal MaxResults As Integer, _
ByVal AccountNumber As String, _
ByVal LastName As String, _

[Code]....

instead of what I expected:

Select count(*) from remitline where lastname = "smith"

What am I doing wrong building up the where clause? I'm using Castle ActiveRecord 2.1

View 1 Replies

Performance Gain In LINQ Query Vs LINQ Stored Procedure?

Aug 6, 2009

if there is that much of a performance gain in running a LINQ stored procedure versus a LINQ query?

View 1 Replies

.net - What Is This Pattern Called

Sep 8, 2009

Private someSub()
If someBoolean = True Then Exit Sub
' do some great work because someBoolean is False
End Sub

I know there is a name for this. The idea is to check something and if it isn't what you want then you stop code processing. I thought it was called "escape pattern", but Google isn't confirming that name.

View 4 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved