本文整理汇总了C#中CreationContext类的典型用法代码示例。如果您正苦于以下问题:C# CreationContext类的具体用法?C# CreationContext怎么用?C# CreationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CreationContext类属于命名空间,在下文中一共展示了CreationContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Request
public virtual object Request(CreationContext context)
{
object instance;
using(rwlock.ForWriting())
{
if (available.Count != 0)
{
instance = available.Pop();
if (instance == null)
{
throw new PoolException("Invalid instance on the pool stack");
}
}
else
{
instance = componentActivator.Create(context);
if (instance == null)
{
throw new PoolException("Activator didn't return a valid instance");
}
}
inUse.Add(instance);
}
return instance;
}
开发者ID:Huddle,项目名称:Castle.Windsor,代码行数:31,代码来源:DefaultPool.cs
示例2: Resolve
public override object Resolve(CreationContext context)
{
HttpContext current = HttpContext.Current;
if (current == null)
throw new InvalidOperationException(
"HttpContext.Current is null. PerWebRequestLifestyle can only be used in ASP.Net");
if (current.Items[PerRequestObjectID] == null)
{
if (!PerWebRequestLifestyleModule.Initialized)
{
string message = "Looks like you forgot to register the http module " +
typeof(PerWebRequestLifestyleModule).FullName +
"\r\nAdd '<add name=\"PerRequestLifestyle\" type=\"Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.MicroKernel\" />' " +
"to the <httpModules> section on your web.config";
throw new ConfigurationErrorsException(message);
}
object instance = base.Resolve(context);
current.Items[PerRequestObjectID] = instance;
PerWebRequestLifestyleModule.RegisterForEviction(this, instance);
}
return current.Items[PerRequestObjectID];
}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:27,代码来源:PerWebRequestLifestyleManager.cs
示例3: ObtainInterceptors
/// <summary>
/// Obtains the interceptors associated with the component.
/// </summary>
/// <param name="kernel">The kernel instance</param>
/// <param name="model">The component model</param>
/// <param name="context">The creation context</param>
/// <returns>interceptors array</returns>
protected IInterceptor[] ObtainInterceptors(IKernel kernel, ComponentModel model, CreationContext context)
{
var interceptors = new List<IInterceptor>();
foreach (IReference<IInterceptor> interceptorRef in GetInterceptorsFor(model))
{
try
{
var interceptor = interceptorRef.Resolve(kernel, context);
SetOnBehalfAware(interceptor as IOnBehalfAware, model);
interceptors.Add(interceptor);
}
catch (Exception e)
{
foreach (var interceptor in interceptors)
{
kernel.ReleaseComponent(interceptor);
}
if(e is InvalidCastException)
{
var message = String.Format(
"An interceptor registered for {0} doesn't implement the {1} interface",
model.Name, typeof(IInterceptor).Name);
throw new DependencyResolverException(message);
}
throw;
}
}
return interceptors.ToArray();
}
开发者ID:pmcg,项目名称:Castle.Windsor,代码行数:39,代码来源:AbstractProxyFactory.cs
示例4: Resolve
public object Resolve(CreationContext context,
ISubDependencyResolver parentResolver,
ComponentModel model,
DependencyModel dependency)
{
return _kernel.ResolveAll(dependency.TargetType.GetElementType(), null);
}
开发者ID:agross,项目名称:fizzbuzz,代码行数:7,代码来源:ArraySubDependencyResolver.cs
示例5: Resolve
public override object Resolve(CreationContext context)
{
lock(slot)
{
var map = (Dictionary<IComponentActivator, object>)Thread.GetData(slot);
if (map == null)
{
map = new Dictionary<IComponentActivator, object>();
Thread.SetData( slot, map );
}
Object instance;
if (!map.TryGetValue(ComponentActivator, out instance))
{
instance = base.Resolve(context);
map.Add(ComponentActivator, instance);
instances.Add(instance);
}
return instance;
}
}
开发者ID:Huddle,项目名称:Castle.Windsor,代码行数:25,代码来源:PerThreadLifestyleManager.cs
示例6: GetSubHandler
protected IHandler GetSubHandler(CreationContext context, Type genericType)
{
lock(type2SubHandler)
{
IHandler handler;
if (type2SubHandler.ContainsKey(genericType))
{
handler = type2SubHandler[genericType];
}
else
{
Type service = ComponentModel.Service.MakeGenericType(context.GenericArguments);
ComponentModel newModel = Kernel.ComponentModelBuilder.BuildModel(
ComponentModel.Name, service, genericType, null);
newModel.ExtendedProperties[ComponentModel.SkipRegistration] = true;
Kernel.AddCustomComponent(newModel);
handler = Kernel.HandlerFactory.Create(newModel);
type2SubHandler[genericType] = handler;
}
return handler;
}
}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:29,代码来源:DefaultGenericHandler.cs
示例7: CanResolve
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model,
DependencyModel dependency)
{
return dependency.TargetType == typeof(IBookStore) && contextHandlerResolver.CanResolve(context, contextHandlerResolver, model,
new DependencyModel(typeof(IBookStore).FullName,
typeof(IBookStore), false));
}
开发者ID:dohansen,项目名称:Windsor,代码行数:7,代码来源:GoodDependencyResolver.cs
示例8: GetAzureServiceConfig
private static IMicrosoftStorageConfig GetAzureServiceConfig(IKernel k, ComponentModel cm, CreationContext cc)
{
var serviceConfig = new DefaultAzureServiceConfigurationProvider(k.Resolve<IAppConfigSettings>()).GetConfigRaw();
var webConfig = serviceConfig["Web"];
return new DictionaryAdapterFactory().GetAdapter<IMicrosoftStorageConfig>(webConfig);
}
开发者ID:ognyandim,项目名称:AzureStrongConfig,代码行数:7,代码来源:ContainerRegistrar.cs
示例9: Resolve
public override object Resolve(CreationContext context)
{
var store = GetStore();
var instance = base.Resolve(context);
if (instance == null)
{
if (context.Handler.ComponentModel.ExtendedProperties[Constants.REG_IS_INSTANCE_KEY] != null)
{
throw new DependencyResolutionException("Cannot find the instance in the context store.");
}
}
else if (store[Model.Name] == null)
{
store[Model.Name] = instance;
store.GetContextInstances().Add(new ContextStoreDependency(Model.Name, instance, this));
_isRegisteredForCleanup = true;
}
if (!_isRegisteredForCleanup)
{
store.GetContextInstances().Add(new ContextStoreDependency(Model.Name, instance, this));
_isRegisteredForCleanup = true;
}
return store[Model.Name];
}
开发者ID:hibri,项目名称:openrasta-stable,代码行数:27,代码来源:ContextStoreLifetime.cs
示例10: Create
public override object Create(IKernel kernel, object instance, ComponentModel model,
CreationContext context, params object[] constructorArguments)
{
var channelHolder = instance as IWcfChannelHolder;
if (channelHolder == null)
{
throw new ArgumentException(string.Format("Given instance is not an {0}", typeof(IWcfChannelHolder)), "instance");
}
if (channelHolder.RealProxy == null)
{
return channelHolder.Channel;
}
if (model.Services.Count() > 1)
{
throw new ArgumentException(string.Format(
"Component {0}, which was designated as a WCF proxy exposes {1} services. The facility currently only supports single-service components.",
model.Name, model.Services.Count()));
}
var isDuplex = IsDuplex(channelHolder.RealProxy);
var proxyOptions = model.ObtainProxyOptions();
var serviceContract = model.GetServiceContract();
var generationOptions = CreateProxyGenerationOptions(serviceContract, proxyOptions, kernel, context);
var additionalInterfaces = GetInterfaces(model.Services, proxyOptions, isDuplex);
var interceptors = GetInterceptors(kernel, model, serviceContract, channelHolder, context);
return generator.CreateInterfaceProxyWithTarget(typeof(IWcfChannelHolder),
additionalInterfaces, channelHolder, generationOptions, interceptors);
}
开发者ID:AdamChang,项目名称:Castle.Facilities.Wcf-READONLY,代码行数:32,代码来源:WcfProxyFactory.cs
示例11: Resolve
public override object Resolve(CreationContext context)
{
var current = HttpContext.Current;
if (current == null)
throw new InvalidOperationException(
"HttpContext.Current is null. PerWebRequestLifestyle can only be used in ASP.Net");
if (current.Items[PerRequestObjectID] == null)
{
if (!PerWebRequestLifestyleModule.Initialized)
{
var message =
string.Format(
"Looks like you forgot to register the http module {0}{1}Add '<add name=\"PerRequestLifestyle\" type=\"Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor\" />' to the <httpModules> section on your web.config",
typeof(PerWebRequestLifestyleModule).FullName, Environment.NewLine);
throw new Exception(message);
}
var instance = base.Resolve(context);
current.Items[PerRequestObjectID] = instance;
PerWebRequestLifestyleModule.RegisterForEviction(this, instance);
}
return current.Items[PerRequestObjectID];
}
开发者ID:mdavis,项目名称:Castle.InversionOfControl,代码行数:27,代码来源:PerWebRequestLifestyleManager.cs
示例12: GetSubHandler
protected IHandler GetSubHandler(CreationContext context, Type genericType)
{
lock (type2SubHandler)
{
IHandler handler;
if (type2SubHandler.ContainsKey(genericType))
{
handler = type2SubHandler[genericType];
}
else
{
Type service = ComponentModel.Service.MakeGenericType(context.GenericArguments);
ComponentModel newModel = Kernel.ComponentModelBuilder.BuildModel(
ComponentModel.Name, service, genericType, null);
newModel.ExtendedProperties[ComponentModel.SkipRegistration] = true;
CloneParentProperties(newModel);
// Create the handler and add to type2SubHandler before we add to the kernel.
// Adding to the kernel could satisfy other dependencies and cause this method
// to be called again which would result in extra instances being created.
handler = Kernel.HandlerFactory.Create(newModel);
type2SubHandler[genericType] = handler;
Kernel.AddCustomComponent(newModel);
}
return handler;
}
}
开发者ID:ralescano,项目名称:castle,代码行数:32,代码来源:DefaultGenericHandler.cs
示例13: Resolve
public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model, DependencyModel dependency)
{
string componentName = null;
if (!_knownDependencies.ContainsKey(dependency))
componentName = dependency.DependencyKey;
return _kernel.Resolve(componentName, dependency.TargetType);
}
开发者ID:gan123,项目名称:RightRecruit,代码行数:7,代码来源:ConventionBasedResolver.cs
示例14: CreateInstance
protected override object CreateInstance(CreationContext context, ConstructorCandidate constructor, object[] arguments)
{
var commandHandler = base.CreateInstance(context, constructor, arguments);
var result = chainBuilder.BuildChain(commandHandler);
return result;
}
开发者ID:gadjio,项目名称:Smi-Playground,代码行数:7,代码来源:CommandHandlerComponentActivator.cs
示例15: CanResolve
/// <inheritdoc />
public bool CanResolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, Castle.Core.ComponentModel model, DependencyModel dependency)
{
if (dependency.TargetType == null)
{
return false;
}
Type genericArgument = null;
if ((dependency.TargetType.IsGenericType) && (dependency.TargetType.GetGenericTypeDefinition() == typeof(IEnumerable<>)))
{
genericArgument = dependency.TargetType.GetGenericArguments()[0];
}
else
{
dependency.TargetType.GetInterfaces().Any(implemented => (implemented.IsGenericType) && (implemented.GetGenericTypeDefinition() == typeof(IEnumerable<>)) &&
((genericArgument = implemented.GetGenericArguments()[0]) != null));
}
if ((genericArgument == null) || (!_kernel.HasComponent(genericArgument)))
{
return false;
}
return true;
}
开发者ID:alien-mcl,项目名称:URSA,代码行数:26,代码来源:AutoClosingCollectionResolver.cs
示例16: Instantiate
protected override object Instantiate(CreationContext context)
{
String factoryId = (String)Model.ExtendedProperties["factoryId"];
String factoryCreate = (String)Model.ExtendedProperties["factoryCreate"];
if (!Kernel.HasComponent(factoryId))
{
String message = String.Format("You have specified a factory ('{2}') " +
"for the component '{0}' {1} but the kernel does not have this " +
"factory registered",
Model.Name, Model.Implementation.FullName, factoryId);
throw new FacilityException(message);
}
IHandler factoryHandler = Kernel.GetHandler(factoryId);
// Let's find out whether the create method is a static or instance method
Type factoryType = factoryHandler.ComponentModel.Implementation;
MethodInfo staticCreateMethod =
factoryType.GetMethod(factoryCreate,
BindingFlags.Public | BindingFlags.Static);
if (staticCreateMethod != null)
{
return Create(null, factoryId, staticCreateMethod, factoryCreate, context);
}
else
{
object factoryInstance = Kernel[factoryId];
MethodInfo instanceCreateMethod =
factoryInstance.GetType().GetMethod(factoryCreate,
BindingFlags.Public | BindingFlags.Instance);
if (instanceCreateMethod == null)
{
factoryInstance = ProxyUtil.GetUnproxiedInstance(factoryInstance);
instanceCreateMethod =
factoryInstance.GetType().GetMethod(factoryCreate,
BindingFlags.Public | BindingFlags.Instance);
}
if (instanceCreateMethod != null)
{
return Create(factoryInstance, factoryId, instanceCreateMethod, factoryCreate, context);
}
else
{
String message = String.Format("You have specified a factory " +
"('{2}' - method to be called: {3}) " +
"for the component '{0}' {1} but we couldn't find the creation method" +
"(neither instance or static method with the name '{3}')",
Model.Name, Model.Implementation.FullName, factoryId, factoryCreate);
throw new FacilityException(message);
}
}
}
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:60,代码来源:FactoryActivator.cs
示例17: Create
/// <summary>
/// Creates the <see cref="ISessionFactory"/> from the configuration
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override object Create(CreationContext context)
{
RaiseCreatingSessionFactory();
var configuration = Model.ExtendedProperties[Constants.SessionFactoryConfiguration]
as Configuration;
return configuration.BuildSessionFactory();
}
开发者ID:kkozmic,项目名称:Castle.Facilities.NHibernateIntegration,代码行数:12,代码来源:SessionFactoryActivator.cs
示例18: SetUpProperties
/// <summary>
/// Source: http://www.symbolsource.org/Public/Metadata/NuGet/Project/Castle.Windsor/3.0.0.3001/Release/.NETFramework,Version%3Dv4.0,Profile%3DClient/Castle.Windsor/Castle.Windsor/MicroKernel/ComponentActivator/DefaultComponentActivator.cs?ImageName=Castle.Windsor
/// </summary>
/// <param name="instance"></param>
/// <param name="context"></param>
protected override void SetUpProperties(object instance, CreationContext context)
{
instance = ProxyUtil.GetUnproxiedInstance(instance);
var resolver = Kernel.Resolver;
foreach (var property in Model.Properties)
{
var value = ObtainPropertyValue(context, property, resolver);
if (value == null)
{
continue;
}
var setMethod = property.Property.GetSetMethod();
try
{
setMethod.Invoke(instance, new[] { value });
}
catch (Exception ex)
{
var message =
String.Format(
"Error setting property {1}.{0} in component {2}. See inner exception for more information. If you don't want Windsor to set this property you can do it by either decorating it with {3} or via registration API.",
property.Property.Name, instance.GetType().Name, Model.Name, typeof(DoNotWireAttribute).Name);
throw new ComponentActivatorException(message, ex, Model);
}
}
}
开发者ID:trondr,项目名称:NMultiTool,代码行数:32,代码来源:StrictComponentActivator.cs
示例19: Resolve
public object Resolve(CreationContext context, ISubDependencyResolver contextHandlerResolver, ComponentModel model,
DependencyModel dependency)
{
return contextHandlerResolver.Resolve(context, contextHandlerResolver, model,
new DependencyModel(DependencyType.Service, typeof(IBookStore).FullName,
typeof(IBookStore), false));
}
开发者ID:n2cms,项目名称:Castle.Windsor,代码行数:7,代码来源:SubResolversShouldNotBeTrustedToBeCorrect.cs
示例20: Resolve
public object Resolve(
CreationContext context,
ISubDependencyResolver parentResolver,
ComponentModel model,
DependencyModel dependency)
{
MockingStrategy strategy = _relatedRepository.GetStrategyFor(dependency);
if (strategy.Instance != null)
return strategy.Instance;
if (strategy.Mock == MockingStrategyType.Mock)
{
//if a dependencywas already registered in the main controller, go and use it
var registration = this._relatedRepository.Kernel.GetHandler(dependency.TargetType);
object resolvedDependencyObject;
if (registration == null)
{
resolvedDependencyObject = MockRepository.GenerateStub(dependency.TargetType);
}
else
{
resolvedDependencyObject = _relatedRepository.Resolve(dependency.TargetType);
}
_relatedRepository.OnMockCreated(resolvedDependencyObject, dependency.DependencyKey);
return resolvedDependencyObject;
}
if (strategy.Mock == MockingStrategyType.Resolve)
return _relatedRepository.Resolve(dependency.TargetType);
return null;
}
开发者ID:alkampfergit,项目名称:ShuppanButsu,代码行数:31,代码来源:AutoMockingDependencyResolver.cs
注:本文中的CreationContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论