|
Hi,
I am new to the singleton pattern. I read that it could be used to load all your website setting and configuration values. I also read that people avoid singletons, and people that do unit testing don't use singleton patterns. Why is this? Are singletons good to use in my scenario? If not, how should I do it then? And how can this be unit tested?
Thanks
Brendan
|
|
|
|
|
First since this is a web related question you should have used the ASP.NET or Web Development forums.
The singleton pattern is a tool like any other, it has its uses under the proper conditions to solve the proper problem. Since the web.config file contains the settings and configuration information for an ASP.NET app you are gaining nothing by trying to use a singleton. On the other hand if some settings are coming from a database, or other source, then a singleton instantiated by the application may be of use.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi,
My apologies for posting it here, but using it to get settings values was just an example. It was posted here because I had some questions regarding the design of the pattern. The main issue that I have is that there is some difficulty in unit testing it. How does one go about unit testing a singleton pattern, and testing all the methods in the .Instance property? Lets say I have something like:
BlogSettings.Instance.Name
How would I unit test .Name?
|
|
|
|
|
Use the Google [^]Pattern
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
The Singleton pattern is more for C++ and is not of much use in C#, especially since the introduction of static classes.
As for unit testing, I hear that they can make using mock objects difficult, but I'm not the one to ask about that.
|
|
|
|
|
PIEBALDconsult wrote: The Singleton pattern is more for C++ and is not of much use in C#
Got a source for that assertion?
|
|
|
|
|
That's my own conclusion.
|
|
|
|
|
I always use the singletom to save the system setting.
Because I never do the unit testing, I do not know why some people avoid singletons, perhaps there is better way than this.
|
|
|
|
|
How can i get MouseEventArgs in datagridview1_CellValidating cause i wanna to use this code in datagridview1_CellValidating:
if (dgvFactorSell.HitTest(e.X, e.Y).ColumnIndex <= dgvFactorSell.CurrentCell.ColumnIndex && dgvFactorSell.HitTest(e.X, e.Y).RowIndex == dgvFactorSell.CurrentRow.Index)
FlagIsBack = true;
private void dgvFactorSell_MouseClick(object sender, MouseEventArgs e)
{
if (dgvFactorSell.HitTest(e.X, e.Y).ColumnIndex <= dgvFactorSell.CurrentCell.ColumnIndex && dgvFactorSell.HitTest(e.X, e.Y).RowIndex == dgvFactorSell.CurrentRow.Index)
FlagIsBack = true;
}
modified on Sunday, June 20, 2010 1:47 PM
|
|
|
|
|
Well I am Noob at english language , I can talk , but I can't understand every thing ,
Excuse me , please! ,
Hope this code Help ...
private void dataGridView1_MouseDown(object sender, MouseEventArgs e)
{
try
{
if (e.Button == MouseButtons.Right)
{
DataGridView.HitTestInfo hit = dataGridView1.HitTest(e.X, e.Y);
dataGridView1.CurrentCell = dataGridView1[0, hit.RowIndex];
}
}
catch
{
}
}
----- Please , Increase the Hit by 1 -----
www.smart-arab.com
I know nothing , I know nothing ...
|
|
|
|
|
|
I have not messagebox result and I really want to use it.
when I type it , it dosen't apear. I search and I find this
public enum messageboxresult
but I didn't khnow how to use it.
|
|
|
|
|
Here is an example of how to get the result from a message box.
private void doSomething()
{
DialogResult theResult = MessageBox.Show("Is this working?", "Well.......",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
if (theResult == DialogResult.Yes)
{
}
}
|
|
|
|
|
In yes or no, this can be use
if (MessageBox.Show("Is this working?", "Well.......", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
}
else
{
}
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
MessageBoxButton buttons = MessageBoxButton.OKCancel;
MessageBoxImage icon = MessageBoxImage.Information;
MessageBoxResult defaultResult = MessageBoxResult.OK;
MessageBoxResult result = MessageBox.Show(message, caption, buttons, icon, defaultResult);
This is however available only in .Net framework 3 and above.
See here.
Quidquid latine dictum sit, altum videtur.
Whatever is said in Latin sounds profound.
|
|
|
|
|
if (DialogResult.Yes == MessageBox.Show("test", "ask", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
{
}
|
|
|
|
|
http://infynet.wordpress.com/2010/08/28/check-message-box-result
hi check this link.
|
|
|
|
|
http://infynet.wordpress.com/2010/08/28/check-message-box-result
hi check this link
|
|
|
|
|
I have a cell (cellIndex:5 and its in edit mode) that user must enter data in it then can go forword to next cell but if user didnt enter any data can only step back(I mean that user can go to all the cells before this Cell, for this example user can go to indexNumbers<5)and if the user didnt enter data must prevent from going to next cell and even next Row.
So please Help out !
|
|
|
|
|
Keep the columns ahead of current one disabled i.e. if user can enter data in column 5 only after entering some data in column 4, keep column 5 disabled initially. Have CellValidating event handler for the DataGridView. In that check for the value in the current cell. If user has entered value in it, enable the columns where user can edit/enter data.
|
|
|
|
|
Thanks for reply
But i want that user be able to go backword even if didnt entered any data in column 5.
|
|
|
|
|
You need something like this in the CellValidating event:
DataGridView dataGridView = sender as DataGridView;
dataGridView.Columns[5].ReadOnly = (e.ColumnIndex == 4 && string.IsNullOrEmpty(e.FormattedValue.ToString()));
User can move to any cell but the editing will be enabled only when the data is entered in the fourth cell.
|
|
|
|
|
Thanks that good but I also want to prevent user from move to next row and also Next cell too.
So now what!
I my self have done the But no use !
Plzzzzz Helpppppppp !
modified on Saturday, June 19, 2010 11:47 PM
|
|
|
|
|
Hi CodeProject.com World!
From My subject u can understand my question
But i will repeat my question in another way also :
Q:
I am attempting to detect a Shift+Tab in the KeyPress event for back
navigation on a Datagridview.
Have any ideas how to compare e.KeyChar to a ShiftTab?
modified on Sunday, June 20, 2010 1:48 PM
|
|
|
|
|
KeyPress event is for the typeable character keys. You can use KeyDown or ProcessCmdKey .
For KeyDown you can check the Shift property of KeyEventArgs[^].
Alternatively you can override the ProcessCmdKey[^] method like this:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == (Keys.Shift | Keys.Tab))
{
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
|
|
|
|