Quick question regarding the use of Singleton lifestyle in Windsor, and Asp.Net MVC. If the following class is registered as a singleton am I correct in thinking that I will have a race condition?
public class UserMapper : IMap
{
public void Map(MyDto dto, MyDomain domain)[code]...
This is a bit of a hypothetical question that has sent me off down the garden path... Say I have a gridview that I'd like to edit... given a method that binds the data..
private void BindGridFirst() { var data = new List<string>() { "A","B","C","D","E","F"[code]...
Now presume that I'm looking at this page, and another user has come along and made some changes to the underlying data, and I now go and click the edit button to edit D...
It's exactly the same, but the data is now changed. Once the UI updates, the user is now in edit mode against row C.Not what the user expected or wanted. How should this scenario be handled to avoid such an issue?
I was in a ASP.NET application has heavy traffic of AJAX requests.Once a user login our web application, a session is created to store information of this user's state. Currently, our solution to keep session data consistent is quite simple and brutal: each request needs to acquire a exclusive lock before being processed.
This works fine for tradition web application. But, when the web application turns to support AJAX, it turns to not efficient. It is quite possible that multiple AJAX requests are sent to server at the same time without reloading the web page. If all AJAX requests are serialized by the exclusive lock, the response is not so quick. Anyway, many AJAX requests that doesn't access same session variables are blocked as well.If we don't have a exclusive lock for each requests, then we need to treat all race condition carefully to avoid dead lock. I'm afraid that would make the code complex and buggy.
So, is there any best practice to keep session data consistent and keep code simple and clean?
I'm trying to set up IoC (Castle Windsor) in my MVC 2 project here, using the section in Pro Asp.net MVC Framework book.
However, I cannot compile after creating a custom controller factory as stated in the book.
This part give me error:[Code]....
Telling me that no suitable method have been found to override?
Does someone know if there's a problem with the code in the book or something changed with recent versions of things (wont suprise me..got some books on MVC here rendered completely useless with the evolution of asp.net mvc)
Recently, I've had some problems with StructureMap. Mostly incomplete documentation, but also they have a habit of drastically changing namespacing, object names, removing methods, and generally changing how the thing works.For now, my code is written using poor man's DI so that I can keep working on it, but I don't want to leave it that way. I took a look at Castle Windsor a while back, but never really tackled it.
With StructureMap, I would derive a custom Registry class where all the mapping is done, a custom Bootstrap class which loads one or more registry classes and initializes them, and then, call Configure on the bootstrap class in Global.asax.How does one go about setting up the matching Castle code? I also need to know how the controller factory is affected. Does Castle provide a replacement, or are we left to write our own, as with StructureMap
I have a class which fetches the data from the database. Say First name, Last name , Telephone number etc and display it in my .aspx page. This data is common to all the users. So i would like to use Singleton pattern so that the object is not created again ,just use the created object for all the users. Can any one help me with the simple code snippet example.
I have a lot of Singleton implementation in asp.net application and want to move my application to IIS Web Garden environment for some performance reasons.
CMIIW, moving to IIS Web Garden with n worker process, there will be one singleton object created in each worker process, which make it not a single object anymore because n > 1.
can I make all those singleton objects, singleton again in IIS Web Garden?
I have a web application where I would like to pull user settings from a database and store them for Global access. Would it make more sense to store the data in a Singleton, or a Session object? What's the difference between the two?Is it better to store the data as an object reference or break it up into value type objects (ints and strings)?
i'm building a web application with asp.net c# and i have a class that i want to use in multiple pages witouth instantiate it every time. I need to load the data in it and never lose them during the user session time. I thought about the singleton-pattern but it shared the instance of the class beetween browsers.
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? or is this not possible - that i'll need to pass the information around as they are needed?
I am working on singleton desing patterns and want some real world example of design patterns.Can you please give me an example how you have used singleton pattern in you project. I would appreciate if you can provide code.
I am creating a singleton object in the first request to the web service and keeping it in the memory. This works fine for first few seconds. If I make a request 5 minutes later, I can see that the singleton object is created again? is my singleton object getting disposed after x no of minutes? how can i make increase the life-time of my object forever ?
public sealed class Singleton { static ServerInstance instance = null; static readonly object padlock = new object(); Singleton() { } public static ServerInstance Instance { get { lock (padlock) { if (instance == null) { instance = new ServerInstance(); } return instance; } } } ~Singleton() { #if DEBUG ExceptionFactory.Fatal("~Singleton() called!"); #endif } } [WebMethod] public string OnReceiveEvent(string objectXmlData, string objectType) { if (!Singleton.Instance.initServerComplete) { InitServer(); } return Singleton.Instance.OnReceiveEvent(objectXmlData, objectType); } public void InitServer() { if (!Singleton.Instance.initServerComplete) { Singleton.Instance.InitServer(); Singleton.Instance.initServerComplete = true; GC.KeepAlive(Singleton.Instance); } }
I'm developing a blog application shared by non-profit organizations. I want each organization to be able to change their own blog settings. I have taken a singleton pattern (from BlogEngine.net) and modified it. (I understand that it is no longer a singleton pattern.) I have tested this approach and it seems to work fine in a development environment. Is this pattern a good practice? Are there issues, which may arise when this is placed in a production environment?
public class UserBlogSettings { private UserBlogSettings() { Load(); } public static UserBlogSettings Instance { get { string cacheKey = "UserBlogSettings-" + HttpContext.Current.Session["userOrgName"].ToString(); object cacheItem = HttpRuntime.Cache[cacheKey] as UserBlogSettings; if (cacheItem == null) { cacheItem = new UserBlogSettings(); HttpRuntime.Cache.Insert(cacheKey, cacheItem, null, DateTime.Now.AddMinutes(1), Cache.NoSlidingExpiration); } return (UserBlogSettings) cacheItem; } } }
I have some confusion with singleton class, below are my some points:
1.Can singleton class have static method?,if yes then how we call that methods? 2.what is main difference between Static class and Singleton Class?
I have created my singleton class as follows:
[Code]....
In Above class structure I have created two method one is Static and second is non static, When I am trying to access Static Method it gives me compile time error.
I have a whole bunch of data access methods where in each one I am doing this
[Code]....
and them moving on with my SqlCommand and SqlDataReader and so on.Is this creating to many instances of an SQLConnection?I was thinking doing this instead. Creating a SqlConnection Manager which would look like this
[Code]....
and then in my database access methods
[Code]....
Is this a good or bad idea and why?Also would this even be neccesary?
I know what Singleton Pattern means and Abstract class means.What I wanted to know was how would this apply to real world.Could anyone give me any good example or simple explanation.Say I have a simple website, why would I use any of the above if any.Why would it simplify my architechture.
I have set the instanceContextMode to single to create a singleton class.I use the join to add a user to the list, and getuserlist() to retrieve the users. I added a service reference opened two browsers , made sure i simulated it such that i am adding two seperate users , and display the users returned by getuserlist. But its always displaying only one user , the current user. I also have a counter
private static int counter = 1 public int returnCounter() { return counter++; }
This is returning incremented values when i open it in different browsers , but the list is always getting overritten. I am running this as a managed windows service, wsHttpBinding , and my client is a website accessing this service.
which one is better in "Session Facade Class" and "Singleton Object" design patterns in ASP.Net? Also, please state the scenarions where specific design pattern is advisable to use.
If I were to use singleton pattern for menu, would that cause that menu to be created once for application session or once for each user session. Obviously, I want something that will create menu items once per application session.
If I have a TextChanged event wired on an asp.net textbox, it will fire everytime I add/remove a character. Is it possible to only fire it if and only if the textbox meets certain conditions such as if the textbox has a non-empty string greater than 5 characters.