yup - that'd be the way .. I love it when someone comes to me and says 'my program does this and this and this but doesnt work' ... and I reply 'a) define doesnt work and b) does each of those seperate parts work independently before you try and put them together, hmmmm ?' - admittedly, I need to learn more about unit testing with frameworks, but I usually do a better job
i never use Dependency Injection in apps. i go through few article with Dependency Injection and found the concept is interesting but believe hard to implement in real life. now i want to implement Dependency Injection in my win form apps.
our company work with many shipping company like UPS, Fedex, Purolator etc for now but in future they have plan to works with many other shipping company. i have developed separate separate class library projects for all those shipping company like UPS, Fedex, Purolator and include those dll into our main form apps. the problem is many time we hard code few things in our code like country code etc.
for example i have one form where 4 buttons are there. like those buttons are "Ship with UPS WorldShip", another button there called "Ship with UPS WebAPI", another button there called "Ship with FedEX Desktop Apps" and another last button called "Ship with Fedex WebAPI".
when user click on UPS WorldShip button then a flat file generate in a folder. when user click on UPS WebAPI button then a request goes to UPS site.
when user click on FedEX WinApps button then a flat file generate in a folder. when user click on FedEX WebAPI button then a request goes to FedEx site.
so what i do now when user click on any button then i call a specific function exist in dll to complete the task.
everything is working fine at my end but the problem is when our company start working with another new shipping company then i have to create another class library for that company.
i said i never use DI ever in my apps and have no experience. so some one guide me how could i handle my situation with DI as a result when a new shipping company will join then i do not have to write any extra code. so guide me how to implement DI in my apps and also guide me with how to handle my situation with sample DI code for guidance.
DI doesn't work this way. If you have new functionality, then you have to write code. So, if you add a new company and that has specific logic, then you will have to write that logic - DI is not a magic bullet. What it would do, is save you having to write any logic to hook it up to your UI, for instance.
If you're going to do this, then I'd suggest that you read a few artioles here on Code Project. This[^] is a good place to start. Beyond that, I'd also consider investigating MEF.
*pre-emptive celebratory nipple tassle jiggle* - Sean Ewington
Adding a bit more emphasis to the previous reply - because you are accessing an external service provider you will always need to write new code for each.
Given your description of how you are implementing this it also seems unlikely that you can generalize it either. Which isn't to say that you are doing it wrong but rather because you are using all the shipping options rather than attempting to normalize it that you won't be able to generalize it. And actually I suspect that if you try to generalize it too much that you could end up with problems.
Tridip Bhattacharjee wrote:
then i have to create another class library for that company.
This doesn't sound like a job for plain DI. It sounds more like a job for MEF which is more of a plug-in architecture.
How much of the code is straight up copy & paste between different companies?
If the code is 99% duplicate, why not just move the differences into a SQL database or XML file and just have a single common engine that reads the params and uses them? I.e. like instead of hardcoding one dll to fedex and another to ups, just have one method where you pass in the URL or whatever?
Even if the code is more like 50% to 75% different, I'd refactor it to a data driven engine instead of a plug-in architecture.
I'm guessing most of the code is identical... go to this URL to create an order, go to this URL to do this, etc.
I would like to come up with C#.NET 3.5 Code review checklist such as Use Properties instead of variables, Use stringbuilder to combine more string values together, Use using block to open connection and so on. Please do share your thoughts to make a complete list. If you have entire list that would be great.
Please note that I'm using .NET Windows Application NOT asp.net.
I'd also say not to throw away a perfectly good StringBuilder just to create another; reuse it if possible.
One thing I've seen done all too often is something like:
for each row in a table
instantiate a StringBuilder (with the default length of 16 no less!)
for each column
Append a comma (possibly with a test first)
Append the value
write it somewhere with ToString()
A better pattern is:
instantiate a StringBuilder (ideally with some estimate of how much space is required by the longest record)
for each row in a table
set the StringBuilder's Length to 0
for each column
AppendFormat the value and a comma
write it somewhere with ToString ( 0 , Length-1 ) to eliminate the extraneous comma
First, assuming that the compiler understands your program no matter how poorly you write it, it is more important that people understand it. From that flows:
Be consistent -- especially in formatting.
Be verbose -- "saving keystrokes" is a bad thing in the long run.
Too many comments is better than too few -- at least they're easier to delete than add.
Avoid premature optimization.
Expect that the developer who might come after you will come after you.
i just want a program that can connect to other program on other computer and also get connected , and i'll make it clear .
i want a program that send and recive data .
like a server and client in one program .
like a chat program .
Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipend = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8000);
string input = textBoxX1.Text;
byte data = newbyte;
data = Encoding.ASCII.GetBytes(input);
string sth = "";
sth = Encoding.ASCII.GetString(data1);
textBoxX2.Text = sth;
i think you know what im done , but this code is doing so far i get of it . i click the listen button in the server side and the server w'll listen to the line so after i fill the textbox in the client form and click the send button it'll send the data and i can get the data perfectly in the server side
but i need two more things to be done , i want the server do the same thing that the client do that's mean send data to client . and i want the client do the same thing as server that's mean get the data from the server .
i hope you get the idea .
both of them do both sending and receiving at the same time .
how that should be possible ?
i dont think is as easy as you said . when im listening to the line by the server computer
how should i respond it ? i know one thing that if the client send the server any message , the server can send any message right a way back to the client after it gets the message from the client . but i dont want to send message right back to the client like this way , i want to have a sperate button on the server that if i clicked it the message w'll send to the client and also recieve the message from the client too .
i dont know , if you get it or not.
Last Visit: 31-Dec-99 18:00 Last Update: 25-Oct-14 2:46