Dependency injection (DI) is a mechanism to implement inversion of control principle. It is to create dynamically (inject) dependencies between different classes based on a configuration file description or loaded programmatically. And the dependencies between software components are not expressed in the static code but determined dynamically at runtime.
Many .NET programmers are asking what DI tools to use ?
We have worked on Spring.NET DI as shown here Dependency Injection using SPRING.NET.
Now we are going to show how to use Dependency injection with Unity, Ninject and try to evidence Strengths and weaknesses of each other.
Evry one can build its own Dependency Injection Framework , so lets start from showing what is DI.
1. Building a dependency Injection Framework
Suppose we have a Product Class :
Lets create a IProductRepository interface and implement it :
Now create an ProductService class to use our Repository
You can find that ProductService depends on ProductRepository. Basically, we have ProductRepository objects creating a dependency between ProductService.
This can be troublesome when we want to run some unit tests on ProductService, especially if repository is something that does complex disk or network access.
So now we’re looking at mocking repository but also somehow intercepting the factory call. Very hard to do.
A solution is to pass the repository in as an argument to the constructor. Now you’ve moved the problem elsewhere, but testing can become lots easier.
We pass the needed dependencies in to the constructor or via property setters, and we make it somebody else’s problem (an object further up the dependency graph, or a dependency injector that builds the dependency graph)
According to SOLID (Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion) , Dependency inversion principle are not respected : One should « Depend upon Abstractions. Do not depend upon concretions ».
So we are going to do Dependency Injection.
So it is very easy to change class implementation without having to change any implemetation somewhere else.
We have used 3 repositories to implement 3 different maners of retrieving data.
2. dependency Injection using Unity
ASP.NET membership is designed to enable you to easily use a number of different membership providers for your ASP.NET applications. You can use the supplied membership providers that are included with the .NET Framework, or you can implement your own providers.
There are two primary reasons for creating a custom membership provider.
- You need to store membership information in a data source that is not supported by the membership providers included with the .NET Framework, such as a MysQL database, an Oracle database, or other data sources.
- You need to manage membership information using a database schema that is different from the database schema used by the providers that ship with the .NET Framework. A common example of this would be membership data that already exists in a SQL Server database for a company or Web site.
In tis tutorial, we are going to implement and configure a custom Membership…
View original post 387 mots de plus
In this article, we are going to walk through how to create, build and deploy your Windows AZURE Cloud Service.
We will create a Cloud Service With ASP.NET Web API using web and worker roles. And finally we will introduce how to communicate between tiers using Service Bus Queues.
It also provides a good introduction on how to quickly create and set up your Windows AZURE Cloud Service for deployment and Source Control Integration
For more information about your Windows AZURE Cloud Service, please take a look at documentation.
Is coming soon, fill in the form to get notified