Wednesday, September 16, 2015

Constructor Dependency Injection

This is the most commonly used Dependency Pattern. The Constructor Injection uses a parameter to inject dependencies. Generally, there is normally one parameterized constructor always. So in this case, the object has no default constructor and we need to pass specified values or dependency at the time of initiation the object.
We will go through one example for better understanding of this type of dependency injection.
IBook.cs
Book.cs
Library.cs
Program.cs

Here,the Injection happens in the constructor, by passing the Service that implements the IBook Interface.

Friday, September 11, 2015

Hooking in C#

In general, a hook is a concept where an application intercepts events, such as messages, mouse actions, and keystrokes.

A hook is a point in the system message-handling mechanism where an application can install a subroutine to monitor the message traffic in the system and process certain types of messages before they reach the target window procedure.

A function that intercepts a particular type of event is known as a hook procedure. A hook procedure can act on each event it receives, and then modify or discard the event.

The following mentioned some example uses for hooks

Monitor messages for debugging purposes
Provide support for recording and playback of macros
Provide support for a help key (F1)
Simulate mouse and keyboard input
Implement a computer-based training (CBT) application

Points to be noted
Hooks tend to slow down the system because they increase the amount of processing the system must perform for each message. You should install a hook only when necessary, and remove it as soon as possible.

Wednesday, September 9, 2015

Dependency Injection

Dependency Injection is all about injecting dependency.
Here, dependency indicates an object that can be used (a service) and injection means passing of dependency to a dependent object (a client).
Dependency Injection is based on software design pattern. Passing the service to client rather than allowing a client to build or find the service is the fundamental requirement of this pattern.
So we can say that dependency injection is the process of removing the dependency of object which creates the independent business objects. In other term, we can say that the process of injecting (converting) coupled (dependent) object into decoupled (independent) object is termed as dependency injection.
There are various types of Dependency Injection which are mentioned below
1. Constructor Injection
2. Setter Injection
3. Interface injection

4. Service Locator Injection

Copyright © Codingnodes,2014.All Rights Reserved.