|
Ok- here is the continuation.
For doing this, I need to supply ISettings instance explicitly. How do I supply it in this scenario ? I had some reading on Singleton Dependency Injection[^], but looks like it won't help much.
|
|
|
|
|
Why wouldn't you just set the dependency as a static property on the class?
|
|
|
|
|
I know it will work. But each time I use Current property, I have to set the settings. I guess it is not a good design.
|
|
|
|
|
What about something like this:
public static SingletonClass
{
private static ISettings _settings;
public static ISettings Settings {get; set;}
static SingletonClass()
{
_settings = new RealImplementationOfSettings();
}
}
What are you using for dependency injection (castle, structure map)?
Disclaimer: I am very new to TDD, I am sure on of the experts would probably tell you to do something completely different...
|
|
|
|
|
Ok - looks good. I will give a try. Thanks
|
|
|
|
|
I have a WebService/WebMethod that has a object array parameter. On of the elements of this array might contain a DBNull. When i try to pass a array with a DBNull element, I get the folllowing message:
The type System.DBNull was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
I have tried XmlInclude and SoapInclude with no success.
Web Service:
[WebMethod]
[System.Xml.Serialization.XmlInclude(typeof(DBNull))]
public string HelloWorld(object[] x) {
return "Hello World";
}
Consumer (Web Site):
object[] myarray = new object[1];
myarray[0] = DBNull.Value;
ServiceWS.Service serv = new ServiceWS.Service();
serv.HelloWorld(myarray);
|
|
|
|
|
Just use null, I dont think DBNull is XmlSerializable.
|
|
|
|
|
On page load in my web project I do processing and database record writing depending on which page was last and how the user has got there. It has dawned on my that I have forgotten about the browser back button...this is now causing my navigation nightmares. Can I tell if the page was arrived at via the browser back button in my C# code behind. If so I don't want to write any DB records. Simple really....
if browser.control = back
{
then nothing...
}
I can bet my last Euro that it is not going to be simple at all...
Any help very welcome..
|
|
|
|
|
Welcome to web development...
The best way to make the page not cachable, and hence it will be loaded every time it is accessed, even with the back button.
|
|
|
|
|
Hi, page load does work everytime but the processing inside needs to be conditional on if the page was assessed using the browser back button...I was wondering if I can tell via C#?
|
|
|
|
|
Maybe check the referrer field?
|
|
|
|
|
The refferer field??
Is this in the URL?
|
|
|
|
|
I am no expert in this area... however I know our web page designer had similar problems.
I could make one suggestion which is if you can keep track of the previous page then if you return to that page there is a chance the back button was pressed - although the user could have navigated there via a link as well I guess...
Oh well as I said I am no expert...
Continuous effort - not strength or intelligence - is the key to unlocking our potential.(Winston Churchill)
|
|
|
|
|
Yes, thats the problem, I'm navigating round the site but need to know if I got there via a browser back button.
|
|
|
|
|
One way of ensuring that the form isn't handled more than once (an order form for example) is:
1. On the page that renders the form for the user to fill in: Set a session variable (named so that it doesn't conflict with other forms/pages) to 1.
2. On the page accepting the post (may be the same page, but method=POST): If the session variable isn't 1, reject the post (show an error message or do something completely different). Otherwise, if the form data is valid and processing succeeds, set the variable to 2. If not, display the form again (again setting the variable to 1), preferably amended with an error message.
This way you won't accept the same form twice. If you don't want to use session variables (if you're on a server farm, for example), use your database instead. For example, create a row with a unique key (Guid/uniqueidentifier is good, but if security is important, add a signature) when the form is first created and include the key (and the signature if you have one) in the form as a hidden field. You then track transaction progress with another field in the record.
This can be elaborated to cater for multi-step transactions as well (including call-backs from, say, credit card payment servers) - but this should give you the general principle. Remember that you should also handle the case when someone jumps right into the middle of your app - and that this may very well be a hacker, faking the entire form contents, the referer field and pretty much everything else (hence the signature idea).
And like another poster noted - welcome to the world of web development - statelessness sucks!
Peter the small turnip
(1) It Has To Work. --RFC 1925[^]
|
|
|
|
|
|
Not sure how that would help but thanks for the post.....
|
|
|
|
|
Hi,
I am using multiple threads in my application and want to abort or close all threads when Exit application or click on Disconnect.But in my case as shown in code, thread status remain alive even I m aborting.Can any1 give me code snippset that how to abort thread successfully :
<code> try
{
if (clog.clnt_th.IsAlive)
{
clog.clnt_th.Abort();
clog.clnt_th.Join(1);
}
if (ClPb.thvidinfo.IsAlive)
{
ClPb.thvidinfo.Abort();
ClPb.thvidinfo.Join(2);
}
if (ClPb.thvideofile.IsAlive)
{
ClPb.thvideofile.Abort();
ClPb.thvideofile.Join(3);
}
if (thvideo.IsAlive)
{
thvideo.Abort();
thvideo.Join(4);
}
}
catch(System.Threading.ThreadAbortException thexp)
{
MessageBox.Show("Time worker thread was aborted: " + DateTime.Now.ToString(),thexp.Message );
}
</code>
thvideo is parent thread and thvideofile and thvidinfo is its child threads.
Shanzay
|
|
|
|
|
You are aborting the thread, so it will throw a ThreadAbortException. Rather exit the thread properly.
|
|
|
|
|
Yes I'm aborting thread as I didnt find any other method for
closing thread.Plz Tell how to abort properly?
Shanzay
|
|
|
|
|
Just return from the ThreadStart method!
|
|
|
|
|
How to return and what to return plz tell clearly
Shanzay
|
|
|
|
|
Hy everyone!
I found the log4net tool which looks very interesting and powerful to me. I also found an article describing how to send log-messages to screen (An Introduction to the log4net logging library, using C#[^].
But the tons of codelines confuse me more than it helps I mean those of the log4net tool
So what I want to do is to write these log-messages described in there to a logfile instead of writing it to screen.
I guess this will be very simple for most of you but at the moment I am stuck. Could someone help me please how to change the code in this article so it writes the messages to a logfile?
Thanks!
Stephan.
|
|
|
|
|
logging to a file is already described in the article you link to. have a quick search for "FileAppender"..
|
|
|
|
|
ups sorry, yes you are right. looks like i didn't see it when quickly reading the article.
thanks for the hint!
|
|
|
|