concept dependency in category c#

This is an excerpt from Manning's book Functional Programming in C#: How to write better C# code.
Listing 7.12. Injecting functions as dependencies
public class DateNotPast : IValidator<BookTransfer> { Func<DateTime> clock; public DateNotPastValidator(Func<DateTime> clock) { this.clock = clock; } public Validation<BookTransfer> Validate(BookTransfer cmd) => cmd.Date.Date < clock().Date ? Errors.TransferDateIsPast : Valid(cmd); }
In the implementation just shown, all the controller’s dependencies are functions. Notice that with this approach, you still have the benefits associated with dependency inversion:

This is an excerpt from Manning's book Dependency Injection in .NET.
In .NET, the garbage collector takes care of a lot of these things for us. A consumer can have its DEPENDENCIES injected into it and use them for as long as it wants. When it’s done, the DEPENDENCIES go out of scope. If no other classes reference them, they’re eligible for garbage collection.
What if two consumers share the same type of DEPENDENCY? Figure 1.14 illustrates that we can choose to inject a separate instance into each consumer, whereas figure 1.15 shows that we may alternatively choose to share a single instance across several consumers. However, from the perspective of the consumer, there’s no difference. According to the LISKOV SUBSTITUTION PRINCIPLE, the consumer must treat all instances of a given interface equally.
Figure 1.14. Each consumer sharing the same type of DEPENDENCY is injected with its own private instance.
![]()
Figure 1.15. Separate consumers sharing the same type of DEPENDENCY are injected with a shared instance.
![]()
Because DEPENDENCIES may be shared, a single consumer can’t possibly control its lifetime. As long as a managed object can go out of scope and be garbage collected, this isn’t much of an issue, but when DEPENDENCIES implement the IDisposable interface, things become much more complicated.
The problem with the ProductService class is that it’s far from self-documenting: we can’t tell which DEPENDENCIES must be present before it will work. In fact, the developers of ProductService may even decide to add more DEPENDENCIES in future versions, so code that works on the current version may fail on a future version, and we aren’t even going to get a compiler error that warns us. SERVICE LOCATOR makes it easy to inadvertently introduce breaking changes.
Directly newing up DEPENDENCIES is just one example of the CONTROL FREAK anti-pattern. Before I get to the analysis and possible ways to fix the problems generated by CONTROL FREAK, let’s look at some more examples to give you a better idea of the context and common failed attempts to address some of the resulting issues.
Listing 12.1. Wiring a list of dependencies
<object id="Entrée" type="Rillettes" /> <object id="MainCourse" type="CordonBleu" /> <object id="Dessert" type="MousseAuChocolat" /> <object id="Meal" type="ThreeCourseMeal"> <constructor-arg ref="Entrée" /> <constructor-arg ref="MainCourse" /> <constructor-arg ref="Dessert" /> </object>

This is an excerpt from Manning's book ASP.NET MVC 2 in Action.
Uses dependencies but isn’t in charge of locating or creating those dependencies
There are only three real lines of code in the RedirectController. Controllers should all be thin, and this is a good example. Only logic related to presenting information to the user belongs in the controller. In this case, the user experiences a redirect; the logic for finding the correct Conference object is a data access issue and doesn’t belong in the controller, so it’s factored into a repository object. The controller demonstrates proper separation of concerns, and it’s easily unit tested because it’s only involved with a single responsibility. We’re able to simulate dependencies using test doubles.
In figure 4.5, you see the unit test passing because we were able to properly simulate this controller’s dependencies and verify that, given the dependencies, the controller will do its job correctly.

This is an excerpt from Manning's book DSLs in Boo: Domain-Specific Languages in .NET.
StructureMap (http://structuremap.sourceforge.net/) is an Inversion of Control (IoC) container, probably the oldest on .NET. An Inversion of Control container is a tool that helps you manage dependencies and lifetimes of objects in your application. You can think about them as very smart factories, although that doesn’t do them justice. You can read more about IoC containers here: http://www.martinfowler.com/articles/injection.html.
We’ve covered a lot of ground, but only at the micro level so far. We’ve talked about how to build a DSL, how to ensure you have a good language, what the design parameters are, and so on. But we haven’t yet touched on the macro level: how to take a DSL and integrate it into an application. Chapter 4 covered this at the micro level (building the languages themselves), but in this chapter we’re going to discuss all that surrounds a DSL in an application. We’ll talk about when and where to integrate a DSL, how to handle errors, how to handle dependencies between scripts, and how to set up a DSL structure that will be easy to work with.

This is an excerpt from Manning's book ASP.NET MVC in Action with MvcContrib, NHibernate, and More.
For most nontrivial projects, you probably won’t place your models in the Models folder. Generally speaking it’s a best practice to keep your domain model in a separate project so that other applications can use it without taking a dependency on your MVC application. We recommend that you put only presentation concerns in the Web Application project.
As we walk through the NextConference action, we notice that we are coordinating dependencies to get the job done. Figure 3.1 illustrates the controller and its dependencies.
There are only three real lines of code in the RedirectController. The controllers should all be thin, and this is a good example. The logic for finding the correct Conference object is a data access issue, and does not belong in the controller, so it’s factored into a repository object. Only logic related to presenting information to the user belongs in the controller. In this case, the user experiences a redirect. This controller demonstrates proper separation of concerns, and it’s easily unit tested because it’s only involved with a single responsibility. We are able to simulate dependencies using test doubles.
In Figure 3.2, you see the unit test passing because we were able to properly simulate this controller’s dependencies and verify that given the dependencies, the controller will do its job correctly.