Dependency Injection and highly coupled objects

Coding Journeyman

power-plugI consider that Dependency Injection (DI) is a very helpful pattern, I love to use it in order to reduce the coupling in my code and it helps me when writing unit tests. But sometimes the code depends on objects that are difficult or impossible to mock.

The HttpContext class of the ASP .NET MVC framework is one example of this kind of object.

I created the following Controller and View as examples:

publicclass IndexController : Controller
{[HttpGet]public ActionResult Index(){string[] languages = HttpContext.Request.UserLanguages;return View(model:languages);}}
@model string[]
@{
    Layout = null;
}
 
<!--DOCTYPE html>
 
<html><head><metaname="viewport"content="width=device-width"/><title>Index</title></head><body>

View original post 759 more words

.NET – What is an Assembly?

Ammar Hasayen - Blog

I usually got a need to do some coding either using PowerShell or .NET. For me, both are similar as PowerShell is built on top of .NET framework, and you can even call helper .NET classes from within your PowerShell code.

I guess a good foundation knowledge in .NET is becoming more and more important for any IT professional. I recall that when i started to learn about .NET framework, I got some difficulties understanding some key concepts. For example, we always hear the word “Assembly”, but for me it is not enough to define it as a DLL you reference or .EXE that you execute, because what I really need to know is what an Assembly actually contains and how the magic happens under the table.

So i decided to share my thoughts about couple of .NET framework concepts and I hope it makes sense to most of you.

View original post 1,025 more words

Understanding WCF in depth : Part – 1

Xamlized

WCF (Windows Communication Foundation) is a mechanism which enables applications to communicate whether they are on the same computer, across the Internet, or on different application platforms.

Thus it allows you to build a Service Oriented application which focuses on integrating across platforms.

Before diving into the basics (ABC’s) of WCF, we should understand the core functionality of WCF which is “WCF Runtime Components”. When we say there arises a need to talk to the outer world we intend of sending “Messages”. Similarly WCF also uses “Messages” to interact.

WCF Runtime Components:

“Message” class is a core part of the WCF Runtime Component.

There are 2 important subparts of WCF Runtime viz.

  1. Channel Stack: This is the block which does the actual work of transferring a message through the channel which then gets picked up at the other end. For now you can consider this to be a black box…

View original post 395 more words

Converting XML or JSON to C# Classes in Visual Studio

Kapil's space

In the Visual Studio 2012 IDE, a new feature is introduce to convert XML document into C# classes as a Serializable type.

In the .NET framework 4.5 there is another Paste Special option is exists in the Edit menu which enables you to copy the XML as C# Classes.

Paste-xml-as-classes.png

Copy the XML  you want to create a class/classes for, place the cursor in a class file on the location you want the code to be added and select the following menu items:

  • Edit.
  • Paste Special.
  • Paste XML as Classes.

And you’re done.

Suppose you have following XML File.
xml-in-vs-2012.jpg

And when you paste the above XML using Paste XML as classes. It will looks like that.

xml-as-classes.jpg

View original post

.NET – What is CLR ?

Ammar Hasayen - Blog

It is so interesting to break down how .NET framework works and uncover the internal components and functionalists. I love breaking things down so i can have better understanding about what I am dealing with.

In a previous blog post, we talked about what an Assembly is. In this blog post, I will be sharing my thoughts about the .NET run time, or CLR.

.NET Common Language Runtime “CLR” is a run-time environment and an execution engine, provided by the .NET framework that provides robust application support with a very small memory footprint and it performs its operations in a very fast way (15,000 managed method calls per second at 27.6MHz).

You can think of CLR as the interface between .NET applications and the operating system. This is way .NET applications are called (Managed Code), because they are managed by the CLR.

clr3

CLR Provides the following services for programming…

View original post 510 more words

Blog at WordPress.com.

Up ↑