• 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/MjIx

Related Code
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
Extension to the HttpClient
Generic Entity Framework 4.0 Base Repository
ForEach Extension method for IEnumerable<T>
Invoke Extension Method
Use of Extension methods to hide "infrastructure code"
PagedList class and paging code for ASP.Net MVC (Nothing new but kind of usefull.)
Null Dot "Operator" Extension Method
Fork of GZIP your Actions in MVC if not used as standard in IIS7 or only use IIS6
Generic Entity Framework 4.0 Base Repository with Paging
Google Analytics helper for ASP.NET Razor
Unity Controller Factory for ASP.NET MVC 3.0
Generic linq-to-sql repository
WCF RIA Services Unity 2.0 DomainService Factory
A Default Entity Framework 4.0 ObjectContext Factory
StringFormat Extension method for HtmlHelper ASP.NET MVC
Custom C# exception class
ASP.NET MVC 4.0 Web API Message logger for .Net 4.0
Email validation with Regular Expression
GZIP your Actions in MVC if not used as standard in IIS7 or only use IIS6
Reflection dynamically get private fields or properties
Url Validation with Regular Expression
Method to hash passwords
Number of sealed / unsealed types in the framework

Unity Service Locator for ASP.NET MVC 3.0 Beta 1

A Unity 2.0 Service Locator which can be used with ASP.Net MVC 3.0

2
1.26k 0 1 0 0 0

public class UnityMvcDependencyResolver : IDependencyResolver
{
    readonly IUnityContainer _container;

    public UnityMvcDependencyResolver(IUnityContainer container)
    {
        _container = container;
    }


    public object GetService(Type serviceType)
    {
        return Resolve(serviceType);
    }


    private object Resolve(Type serviceType, string key = null)
    {
        try
        {
            return _container.Resolve(serviceType, key);
        }
        catch (Exception ex)
        {
            throw new InstanceNotFoundException(ex.Message, ex);
        }
    }


    public IEnumerable<object> GetServices(Type serviceType)
    {
        return _container.ResolveAll(serviceType);
    }

Use the global.asax Application_Start to setup the IDependencyResolver you want ASP.NET MVC 3.0 to use:

var container = new UnityContainer();

//...  register types to the UnityContainer

DependencyResolver.SetResolver(new UnityMvcDependencyResolver(container));

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

.net

Mark '.net' tag as 'like'

Mark '.net' tag as 'ignore'

aspmvc

Mark 'aspmvc' tag as 'like'

Mark 'aspmvc' tag as 'ignore'

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

service-locator

Mark 'service-locator' tag as 'like'

Mark 'service-locator' tag as 'ignore'


 @fredrikn "I'm the master"
3.11k
August 01, 2010 9:35 AM
edited October 24, 2010 1:03 PM

Fork

 Unity Service Locator for ASP.NET MVC 3.0 Beta 1 -  @fredrikn Sunday 01, 2010 9:35 AM


1 Feedback

Thanks... saved me a few minutes :) -  David W Martines Saturday 28, 2010 2:43 PM

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