本文整理汇总了C#中Castle.MicroKernel.CreationContext类的典型用法代码示例。如果您正苦于以下问题:C# CreationContext类的具体用法?C# CreationContext怎么用?C# CreationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CreationContext类属于Castle.MicroKernel命名空间,在下文中一共展示了CreationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: Resolve
public object Resolve(CreationContext context, ISubDependencyResolver parentResolver,
ComponentModel model,
DependencyModel dependency)
{
Type t = dependency.TargetType.GetGenericArguments()[0];
return kernel.ResolveAll(t, null);
}
示例3: Instantiate
protected override object Instantiate(CreationContext context)
{
String accessor = (String) Model.ExtendedProperties["instance.accessor"];
PropertyInfo pi = Model.Implementation.GetProperty(
accessor, BindingFlags.Public|BindingFlags.Static );
if (pi == null)
{
String message = String.Format("You have specified an instance accessor " +
"for the component '{0}' {1} which could not be found (no public " +
"static property has this name)", Model.Name, Model.Implementation.FullName);
throw new FacilityException(message);
}
if (!pi.CanRead)
{
String message = String.Format("You have specified an instance accessor " +
"for the component '{0}' {1} which is write-only",
Model.Name, Model.Implementation.FullName);
throw new FacilityException(message);
}
try
{
return pi.GetValue( null, new object[0] );
}
catch(Exception ex)
{
String message = String.Format("The instance accessor " +
"invocation failed for '{0}' {1}",
Model.Name, Model.Implementation.FullName);
throw new FacilityException(message, ex);
}
}
示例4: Resolve
public override object Resolve(CreationContext context)
{
var current = HttpContext.Current;
if (current == null)
throw new InvalidOperationException("HttpContext.Current is null. PerHttpApplicationLifestyle can only be used in ASP.NET");
var app = current.ApplicationInstance;
var lifestyleModule = app.Modules
.Cast<string>()
.Select(k => app.Modules[k])
.OfType<PerHttpApplicationLifestyleModule>()
.FirstOrDefault();
if (lifestyleModule == null) {
var message = string.Format("Looks like you forgot to register the http module {0}" +
"\r\nAdd '<add name=\"PerHttpApplicationLifestyle\" type=\"{1}\" />' " +
"to the <httpModules> section on your web.config",
typeof (PerWebRequestLifestyleModule).FullName,
typeof (PerWebRequestLifestyleModule).AssemblyQualifiedName);
throw new ConfigurationErrorsException(message);
}
if (!lifestyleModule.HasComponent(PerAppObjectID)) {
var instance = base.Resolve(context);
lifestyleModule[PerAppObjectID] = instance;
app.Disposed += (sender, args) => base.Release(instance);
}
return lifestyleModule[PerAppObjectID];
}
示例5: 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);
}
}
}
示例6: Resolve
public object Resolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
DependencyModel dependency)
{
Type elementType = dependency.TargetType.GetElementType();
Array all = kernel.ResolveAll(elementType, new Hashtable());
return all;
}
示例7: InternalCreate
protected override object InternalCreate(CreationContext context)
{
String fileName = (String) Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_FILE];
bool isEmbedded = (bool) Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_EMBEDDED];
String connectionString = (String) Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_CONNECTION_STRING];
DomSqlMapBuilder domSqlMapBuilder = new DomSqlMapBuilder();
ISqlMapper sqlMapper;
if (isEmbedded)
{
XmlDocument sqlMapConfig = Resources.GetEmbeddedResourceAsXmlDocument(fileName);
sqlMapper = domSqlMapBuilder.Configure(sqlMapConfig);
}
else
{
sqlMapper = domSqlMapBuilder.Configure(fileName);
}
if (connectionString != null && connectionString.Length > 0)
{
sqlMapper.DataSource.ConnectionString = connectionString;
}
if (sqlMapper != null)
{
return sqlMapper;
}
else
{
throw new FacilityException(string.Format("The IBatisNetIntegration Facility was unable to successfully configure SqlMapper ID [{0}] with File [{1}] that was set to Embedded [{2}].", Model.Name, Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_FILE].ToString(), Model.ExtendedProperties[IBatisNetFacility.MAPPER_CONFIG_EMBEDDED].ToString()));
}
}
示例8: 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];
}
示例9: Resolve
public object Resolve(CreationContext context,
ISubDependencyResolver parentResolver,
ComponentModel model,
DependencyModel dependency)
{
return _kernel.ResolveAll(dependency.TargetType.GetElementType(), null);
}
示例10: 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));
}
示例11: CanResolve
public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
DependencyModel dependency)
{
return Context.CurrentUser != null &&
dependency.TargetType == typeof (INotifications);
}
示例12: Resolve
/// <summary>
/// Resolves the specified context.
/// </summary>
/// <param name="context">The context.</param>
/// <returns></returns>
public override object Resolve(CreationContext context)
{
if (HttpContext.Current == null)
{
throw new InvalidOperationException("HttpContext.Current is null. ScopeWebRequestLifestyleManager can only be used in ASP.NET");
}
string name = (ComponentActivator as AbstractComponentActivator).Model.Name;
if (_requestScope[name] == null)
{
if (!ScopeLifestyleModule.Initialized)
{
string message = "Looks like you forgot to register the http module " +
typeof(ScopeLifestyleModule).FullName +
"\r\nAdd '<add name=\"ScopeLifestyleModule\" type=\"Castle.Igloo.LifestyleManager.ScopeLifestyleModule, Castle.Igloo\" />' " +
"to the <httpModules> section on your web.config";
{
throw new ConfigurationErrorsException(message);
}
}
object instance = base.Resolve(context);
_requestScope.Add(name, instance);
ScopeLifestyleModule.RegisterForRequestEviction(this, name, instance);
}
return _requestScope[name];
}
示例13: Resolve
public object Resolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
DependencyModel dependency)
{
if (dependency.TargetType == typeof (ISession))
return SessionFactory.OpenSession();
return SessionFactory.OpenStatelessSession();
}
示例14: Instantiate
protected override object Instantiate(CreationContext context)
{
object instance = base.Instantiate(context);
Marshal(instance, Model);
return instance;
}
示例15: CanResolve
public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver,
ComponentModel model,
DependencyModel dependency)
{
return dependency.TargetType != null &&
dependency.TargetType.IsArray &&
dependency.TargetType.GetElementType().IsInterface;
}