- source.zip
- MetaContainer
- Libs
- Autofac.dll
- Castle.Core.dll
- Castle.DynamicProxy2.dll
- Castle.MicroKernel.dll
- Castle.Windsor.dll
- Microsoft.Practices.ObjectBuilder2.dll
- Microsoft.Practices.ServiceLocation.dll
- Microsoft.Practices.Unity.dll
- nunit.framework.dll
- Rhino.Mocks.dll
- MetaContainer.Autofac
- MetaContainer.Castle
- MetaContainer.sln
- MetaContainer.Unity
- MetaContainer.vssscc
- MetaContainer
- Samples.MetaContainer.MoneyExchangeSample.ConsoleHost
- Samples.MetaContainer.MoneyExchangeSample.ContainerAbstraction
- Samples.MetaContainer.MoneyExchangeSample.DomainModel
- Tests.MetaContainer.Autofac
- Tests.MetaContainer.Castle
- Tests.MetaContainer.Unity
- Tests.MetaContainer
|
using System;
using System.Collections;
using Castle.Core;
using Castle.MicroKernel;
namespace MetaContainer.Castle
{
/// <summary>
/// Provides common method used throughout the assembly.
/// </summary>
internal static class Common
{
/// <summary>
/// Registers factory method mapping in Castle kernel.
/// </summary>
/// <param name="kernel">Kernel in which method should be registered.</param>
/// <param name="from">Service interface type.</param>
/// <param name="factoryMethod">A method producing service implementations.</param>
/// <param name="name">Name under which mapping should be registred.</param>
/// <param name="scope">Scope/lifestyle of registration.</param>
internal static void RegisterInKernel(IKernel kernel, Type from, Func<string, object> factoryMethod, string name, Scope scope)
{
IDictionary properties = new Hashtable();
properties["factoryMethod"] = factoryMethod;
name = name ?? Guid.NewGuid().ToString();
ComponentModel serviceModel = kernel.ComponentModelBuilder.BuildModel(
name, from, from, properties);
serviceModel.LifestyleType = scope == Scope.Transient ? LifestyleType.Transient : LifestyleType.Singleton;
serviceModel.CustomComponentActivator = typeof(FactoryMethodActivator);
kernel.AddCustomComponent(serviceModel);
}
/// <summary>
/// Maps MetaContainer scope representation (<see cref="Scope"/>) to Castle's lifestyle (<see cref="LifestyleType"/>).
/// </summary>
/// <param name="scope">Lifestyle/scope in MetaContainer's terms.</param>
/// <returns>Lifestyle/scope in Castle's terms.</returns>
internal static LifestyleType MapLifestyle(Scope scope)
{
return scope == Scope.Transient ? LifestyleType.Transient : LifestyleType.Singleton;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.