Monday, 26 August 2013

Unity Generic Container Interface Implementation

An implementation of the IIoCGenericContainer interface for the Unity container.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;

namespace IoC
{
public class UnityGenericContainer : IIoCGenericContainer
{
private IUnityContainer container;

public UnityGenericContainer(IUnityContainer container)
{
this.container = container;
}

#region IGenericContainer Members

public TType Resolve<TType>()
{
return this.container.Resolve<TType>();
}

public TType TryResolve<TType>()
{
TType result;

try
{
result = this.container.Resolve<TType>();
}
catch (Exception)
{
result = default(TType);
}

return result;
}

public void RegisterType<T>()
{
this.container.RegisterType<T>();
}

public void RegisterType<T>(bool singleton)
{
if (singleton)
{
this.container.RegisterType<T>(new ContainerControlledLifetimeManager());
}
else
{
this.container.RegisterType<T>();
}
}

public void RegisterType<TFrom, TTo>(bool singleton) where TTo : TFrom
{
if (singleton)
{
this.container.RegisterType<TFrom, TTo>(new ContainerControlledLifetimeManager());
}
else
{
this.container.RegisterType<TFrom, TTo>();
}
}

public void RegisterInstance<TInterface>(TInterface instance, bool singleton)
{
if (singleton)
{
this.container.RegisterInstance<TInterface>(instance, new ContainerControlledLifetimeManager());
}
else
{
this.container.RegisterInstance<TInterface>(instance);
}
}

public void RegisterInstance<TInterface>(TInterface instance)
{
this.container.RegisterInstance<TInterface>(instance);
}


public object Resolve(Type t)
{
return this.container.Resolve(t);
}

public IEnumerable<object> ResolveAll(Type t)
{
return this.container.ResolveAll(t);
}

public IEnumerable<T> ResolveAll<T>()
{
return this.container.ResolveAll<T>();
}

public void RegisterType<TFrom, TTo>() where TTo : TFrom
{
this.container.RegisterType<TFrom, TTo>();
}

public void RegisterInstance(object instance)
{
this.container.RegisterInstance(instance);
}

#endregion
}
}

Sunday, 25 August 2013

Ninject Generic Container Interface Implementation

An implementation of the IIoCGenericContainer interface for the Ninject container.

using System;
using Ninject;
using System.Collections.Generic;

namespace IoC
{
public class NinjectGenericContainer : IIoCGenericContainer
{
IKernel kernel;

public NinjectGenericContainer(IKernel kernel)
{
this.kernel = kernel;
}



public object Resolve(Type t)
{
return this.kernel.Get(t);
}

public T Resolve<T>()
{
return this.kernel.Get<T>();
}

public T TryResolve<T>()
{
return this.kernel.TryGet<T>();
}

public IEnumerable<object> ResolveAll(Type t)
{
return this.kernel.GetAll(t);
}

public IEnumerable<T> ResolveAll<T>()
{
return this.kernel.GetAll<T>();
}

public void RegisterType<T>()
{
this.kernel.Bind<T>().ToSelf();
}

public void RegisterType<T>(bool singleton)
{
if (singleton)
{
this.kernel.Bind<T>().ToSelf().InSingletonScope();
}
else
{
this.RegisterType<T>();
}
}

public void RegisterType<TFrom, TTo>() where TTo : TFrom
{
this.kernel.Bind<TFrom>().To<TTo>();
}

public void RegisterType<TFrom, TTo>(bool singleton) where TTo : TFrom
{
if (singleton)
{
this.kernel.Bind<TFrom>().To<TTo>().InSingletonScope();
}
else
{
RegisterType<TFrom, TTo>();
}
}

public void RegisterInstance(object instance)
{
this.kernel.Inject(instance);
}

public void RegisterInstance<TInterface>(TInterface instance)
{
this.kernel.Inject(instance);
}

public void RegisterInstance<TInterface>(TInterface instance, bool singleton)
{
throw new NotImplementedException();
}
}
}

IoC Generic Container Interface

A generic interface that can be implemented for different IoC containers. By using the interface switching between container implementations would be easy, particularly helpfull when testing the use of a container.

using System;
using System.Collections.Generic;

namespace IoC
{
public interface IIoCGenericContainer
{
object Resolve(Type t);

T Resolve<T>();

T TryResolve<T>();

IEnumerable<object> ResolveAll(Type t);

IEnumerable<T> ResolveAll<T>();

void RegisterType<T>();

void RegisterType<T>(bool singleton);

void RegisterType<TFrom, TTo>() where TTo : TFrom;

void RegisterType<TFrom, TTo>(bool singleton) where TTo : TFrom;

void RegisterInstance(object instance);

void RegisterInstance<TInterface>(TInterface instance);

void RegisterInstance<TInterface>(TInterface instance, bool singleton);
}
}

Monday, 30 April 2012

Use Windows Phone GPS Emulator with a desktop application

Windows phone GPS emulator as the name suggests is a GPS emulator desktop application that helps you debug your windows phone 7 gps client application. You can get hold of the GPS Emulator here.

Friday, 20 April 2012

Place Google ads inline your blog post using XsltPlugin

Create an xml file where you will be keeping the adsense code for your ads. Between the CDATA sections you should put your adsense code for each ad. Give it a name ie. “ads.xml” and save it. It should be similar to this:

Sunday, 19 February 2012

Insert Rss feed items using the WLW XsltPlugin

Choose an rss feed address. For the sake of this example we are choosing the rss feed of Mashable(http://feeds.mashable.com/Mashable). Now using a text editor copy and paste the following piece of xslt into a file and save it as ie. rsslinks.xslt:

Wednesday, 15 February 2012

Using NuGet with a central repository

It may be suited  to your development process to use a central repository where all the NuGet packages you use in different projects are kept. That way you don’t have various packages scattered around in your pc or if you archive references you can keep doing so or if you don’t have internet connection you can still use existing packages from the central repository.

Monday, 13 February 2012

Xslt Plugin for Windows Live Writer

A plugin for the Windows LIve Writer blogging software was developed. A simple but yet a very powerful plugin that can make your blog posts more pretty and customised to your liking. The Xslt plugin can transform your content data. The plugin offers the benefit of preparing an xslt template that can be reused, can have css formatting and can be applied to the matched xml content data.

Tuesday, 4 January 2011

Search trip from IDisposable to RDL

I opened the codeproject’s newsletter I am subscribed and picked a few articles. I picked those that were relevant to the things I am interested more,  I have worked in the past or relate to an idea that I am working on it. At first I read this article about IDisposable because an article about IDisposable is always interesting. It presents the right way to use this interface or at least it attempts to.

Saturday, 25 December 2010

How to use CLR in the MSSQL server

To use the CLR in MSSQL Server you need to enable CLR Integration first. It can be enabled in the sql server surface area configuration.

Thursday, 20 May 2010

A T4 Generator Tool for VS Express

T4 stands for Text Templating Transformation Toolkit which is a transformation engine built into all VS studio editions. In a few words, you can write a text template file which consists of plain text and source code wrapped around the T4 language notation. The T4 notation is similar to the ASP.NET design page source code. You indicate directives by using <#@ tags, statements with <# tags, and expressions with <#= tags. Below is a simple T4 template.

<#@ template debug="true" language="C#v3.5"#>
<#@ Import Namespace="System.Linq" #>
<#@ Assembly Name="System.Core,Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" #>
<#@ output extension=".cs" #>
<# WriteLine(@"Hello World");#>

Sunday, 18 April 2010

Reverse Engineer a Web Service from the existing WSDL

Sometimes you need to create the web service methods and you only have the web service description file(wsdl) as a staring point. You can utilise the wsdl.exe tool to generate the web service's server stub methods. This file exists in Program Files\Microsoft SDKs\Windows\v6.0A\bin\ if you have the VS express edition installed or somewhere in the VS installation folders if you have other editions. Just by running :

Tuesday, 30 March 2010

How to use Subsonic 3 T4 templates in VS Express

Subsonic is an ORM tool that works up your database access and can speed your development cycle. It can be downloaded from . To use subsonic in your visual studio express project you can follow the steps below: