• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

http://4kcan.com/s/MTY3

Related Code
A Default Entity Framework 4.0 ObjectContext Factory
Simple light ObjectFactory using Unity
Generic Entity Framework 4.0 Base Repository
ForEach Extension method for IEnumerable<T>
Invoke Extension Method
Use of Extension methods to hide "infrastructure code"
Unity Service Locator for ASP.NET MVC 3.0 Beta 1
Null Dot "Operator" Extension Method
Generic Entity Framework 4.0 Base Repository with Paging
WCF Service factory for using Microsoft Unity 2.0 to create an instance of a Service
Unity Controller Factory for ASP.NET MVC 3.0
Generic linq-to-sql repository
UnitOfWork Action filter for ASP.NET MVC and nHibernate
Make sure the web.config pages/namespace can be used together with ASP.NET MVC 3 P1 and Razor
HttpContextLifetimeManager for Unity
Custom C# exception class
Email validation with Regular Expression
Reflection dynamically get private fields or properties
Url Validation with Regular Expression
Method to hash passwords
Number of sealed / unsealed types in the framework
Extension to the HttpClient

WCF RIA Services Unity 2.0 DomainService Factory

A WCF RIA Services DomainService Factory using Microsoft Pattern&Practices Unity 2.0 IoC Container

1
880 0 0 0 0 0

public class UnityDomainServiceFactory : IDomainServiceFactory
{
    private IUnityContainer _unityContainer = null;

    public UnityDomainServiceFactory(IUnityContainer unityContainer)
    {
        if (unityContainer == null)
           throw new ArgumentNullException("unityContainer");

        _unityContainer = unityContainer;
    }

    public DomainService CreateDomainService(Type domainServiceType, DomainServiceContext context)
    {
        var service = _unityContainer.Resolve(domainServiceType) as DomainService;
        service.Initialize(context);

        return service;
    }

    public void ReleaseDomainService(DomainService domainService)
    {
       domainService.Dispose();
    }
}

How to use the Code:

You can for example in the Global.asax add the following to the Application_Start:

protected void Application_Start(object sender, EventArgs e)
{
   UnityContainerConfiguration.Configure();

   DomainService.Factory = new UnityDomainServiceFactory(UnityContainerConfiguration.Container);
}

Here is the code for the UnityContainerConfiguration class used to setup the Unity container:

public static class UnityContainerConfiguration
{
    public readonly static IUnityContainer Container = new UnityContainer();


    public static IUnityContainer Configure()
    {

        Container.RegisterType<MemberDomainService>();
        Container.RegisterType<IMemberRepository, MemberRepository>();
        //...

        return Container;
    }
}

Share: twitter | facebook   Action: used | fork | flag

.net

Mark '.net' tag as 'like'

Mark '.net' tag as 'ignore'

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

factory

Mark 'factory' tag as 'like'

Mark 'factory' tag as 'ignore'

unity

Mark 'unity' tag as 'like'

Mark 'unity' tag as 'ignore'

wcf-ria-services

Mark 'wcf-ria-services' tag as 'like'

Mark 'wcf-ria-services' tag as 'ignore'


 @fredrikn "I'm the master"
3.11k
July 10, 2010 10:13 AM
edited July 15, 2010 11:19 PM

Fork

 WCF RIA Services Unity 2.0 DomainService Factory -  @fredrikn Saturday 10, 2010 10:13 AM


0 Feedback


You must log in before you can give any feedback


0 Discussion(s)

Newest Oldest

You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010