Jump to content

Recommended Posts

Posted

What is dependency injection?

In a nutshell, dependency injection is a design pattern where external dependencies are “injected” into components rather than baked in.

If that made your eyes glaze over, think about it like this: imagine your friend asked you to drive him to the supermarket:

 

 

You would probably just hop in your car and take him:

 

 

But what if your friend asked you to drive him and his 5 friends to the supermarket, but your car only seats 4?

3.jpg

You would need a bigger car, right? Well, the good news is that since most cars implement the same interface (steering wheel, accelerator, brakes, etc.), you’re not only capable of driving your own car but many other cars as well. So if you had access to say, your mom’s minivan, you could complete the trip:

4.jpg

At the root of it, that’s what dependency injection is all about. Instead of you being stuck having to always use your car for your trips, you will be given the correct car to use based on the circumstances.

Bringing this back into software terminology, in the analogy above you (the driver) are a class and the car is your dependency. You depend on the car to drive your friend(s) to the supermarket. It doesn’t matter which car you use, so long as it’s familiar to you. Without dependency injection, the You class might look something like this:

 

1 2 3 4 5 6 7 8 9 10 11

public class You {
private Car myCar = new Car();
 
public void Drive(IList<Person> passengers, Location destination)
{
foreach (var passenger in passengers)
myCar.AddPassenger(passenger);
 
myCar.Drive(destination);
}
}
view raw gistfile1.cs hosted with ❤ by GitHub

 

Notice how you’ll always be using that particular instance of Car to complete the trip. With dependency injection however, the You class would look something like this:

 

 

 

 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

				
public class You {
private ICar myCar;
 
public You(ICar car)
{
myCar = car;
}
 
public void Drive(IList<Person> passengers, Location destination)
{
foreach (var passenger in passengers)
myCar.AddPassenger(passenger);
 
myCar.Drive(destination);
}
}

 

  • Replies 221
  • Created
  • Last Reply

Top Posters In This Topic

  • dotnetrockz

    32

  • puli_keka

    31

  • karna11

    28

  • Suhaas

    16

Posted

first time Parallel.For vaada .. endhi saami intha super undhi.. 

Parallel.For(0,100,ctr=> {if (Request_chainpl_partnerwcf_net(out response))   //ee method lo I do a HttpWebRequest call for rest webservice
                                            {
                                                 response.Close();
                                             }
                    });
 
inthaku mundu for loop vaaduthunde   parallel.for cheyagane asalu rachu completing 100 webrequests in like 10 seconds.. previously it used to take more than couple of minutes ala. 
Posted

picha pichaga interset vasthundi parallel programming meeda..  

Posted

 

first time Parallel.For vaada .. endhi saami intha super undhi.. 

Parallel.For(0,100,ctr=> {if (Request_chainpl_partnerwcf_net(out response))   //ee method lo I do a HttpWebRequest call for rest webservice
                                            {
                                                 response.Close();
                                             }
                    });
 
inthaku mundu for loop vaaduthunde   parallel.for cheyagane asalu rachu completing 100 webrequests in like 10 seconds.. previously it used to take more than couple of minutes ala. 

 

GP.   web request lu eppudu trigger avuthundhi? i mean application lo

Posted

Different question bhaiyya. 

 

memu MVC5 using. 

 

Registration page undhi with a form. 

Page load aiynappudu. Focus "PostCode" aney textbox ki velthundhi. 

memu code em focus pedthalemu. this textbox is just like any other textbox on the form . why focus is going to this textbox. 

 

 

How to prevent any focus on the form. Naaku focus ae oddhu asalu.  

how can we do this?

 

brahmam_style10_1.gif?1290368350

Posted

picha pichaga interset vasthundi parallel programming meeda..  

more info please

Posted

GP. web request lu eppudu trigger avuthundhi? i mean application lo


Not in dev code. I wanted to generate load.. Oka request ni fiddler lo capture chesi request to code add on undi which generates c# code.. Same request ni oka 100 times for lo petti execute chestha which I changed to parallel.For
Posted

more info please


Multi threading, task parallel library lock semaphore concepts nerchukundam anukuntunna.. Last ki operating systems text book kuda chuduvudam ani fix ayya by galvin gagne
Posted

lets share somethings about testing.....(we'll again get back to our .net concepts)

 

 

 

mee firm lo testing ela chestharu.....i mean i saw people talking abt using 3rd party frameworks..like nunit.....but actual ga unit testing ki maname test cases list chesukoni okko case ki set of parameters tho test chesthe saripoada?

Posted

lets share somethings about testing.....(we'll again get back to our .net concepts)



mee firm lo testing ela chestharu.....i mean i saw people talking abt using 3rd party frameworks..like nunit.....but actual ga unit testing ki maname test cases list chesukoni okko case ki set of parameters tho test chesthe saripoada?


We use msunit which is part of vs test project.. We create common methods to get data from dB make Webservice call etc. Then we create [TestMethod] s for bvt functional negative path and in every test get parameters use common methods to make call and to Assert
Will share more details later
Posted

brahmam_style10_1.gif?1290368350

 

Naa question ki evari daggaranna answer undha?

Posted

brahmam_style10_1.gif?1290368350

 

Naa question ki evari daggaranna answer undha?

im no expert  on mvc but paricularly aa textbox midha focus undhi ante did u check the jquery or javascript code for onload method or did u define any attributes on tghis particular textbox.....

 

is "PostCode" name of that particular txtbox?

Posted

Need help .Net 1.1 to 4.0 project migration.  So many people advised me to upgrade to 2.0 first then to 4.0 but I just converted the project in VS 2005 and it is giving me 120 errors! Any extra suggestions please.

Posted

Need help .Net 1.1 to 4.0 project migration.  So many people advised me to upgrade to 2.0 first then to 4.0 but I just converted the project in VS 2005 and it is giving me 120 errors! Any extra suggestions please.

post the errors here...mostly they will be assembly refernce errors or some components which dont work no more in 2.0/4.0

×
×
  • Create New...