当前位置: 首页>>代码示例>>C#>>正文


C# MicroKernel.CreationContext类代码示例

本文整理汇总了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();
		}
开发者ID:ralescano,项目名称:castle,代码行数:12,代码来源:SessionFactoryActivator.cs

示例2: Resolve

 public object Resolve(CreationContext context, ISubDependencyResolver parentResolver,
     ComponentModel model,
     DependencyModel dependency)
 {
     Type t = dependency.TargetType.GetGenericArguments()[0];
     return kernel.ResolveAll(t, null);
 }
开发者ID:emmekappa,项目名称:horn_src,代码行数:7,代码来源:EnumerableResolver.cs

示例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);
			}
		}
开发者ID:ralescano,项目名称:castle,代码行数:35,代码来源:AccessorActivator.cs

示例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];
        }
开发者ID:ruanzx,项目名称:mausch,代码行数:29,代码来源:PerHttpApplicationLifestyleManager.cs

示例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);
				}
			}
		}
开发者ID:ralescano,项目名称:castle,代码行数:60,代码来源:FactoryActivator.cs

示例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;
		}
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:7,代码来源:ArrayOfComponentsResolver.cs

示例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()));
			}
		}
开发者ID:atczyc,项目名称:castle,代码行数:34,代码来源:SqlMapActivator.cs

示例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];
        }
开发者ID:neilrees,项目名称:openrasta-stable,代码行数:27,代码来源:ContextStoreLifetime.cs

示例9: Resolve

		public object Resolve(CreationContext context,
		                      ISubDependencyResolver parentResolver,
		                      ComponentModel model,
		                      DependencyModel dependency)
		{
			return _kernel.ResolveAll(dependency.TargetType.GetElementType(), null);
		}
开发者ID:Slesa,项目名称:Playground,代码行数:7,代码来源:ArraySubDependencyResolver.cs

示例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));
			}
开发者ID:ralescano,项目名称:castle,代码行数:7,代码来源:SubResolversShouldNotBeTrustedToBeCorrect.cs

示例11: CanResolve

        public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
                               DependencyModel dependency)
        {

            return Context.CurrentUser != null &&
                   dependency.TargetType == typeof (INotifications);
        }
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:7,代码来源:NotificationResolver.cs

示例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];
        }
开发者ID:atczyc,项目名称:castle,代码行数:36,代码来源:ScopeWebRequestLifestyleManager.cs

示例13: Resolve

 public object Resolve(CreationContext context, ISubDependencyResolver parentResolver, ComponentModel model,
     DependencyModel dependency)
 {
     if (dependency.TargetType == typeof (ISession))
         return SessionFactory.OpenSession();
     return SessionFactory.OpenStatelessSession();
 }
开发者ID:brumschlag,项目名称:rhino-tools,代码行数:7,代码来源:SessionResolver.cs

示例14: Instantiate

		protected override object Instantiate(CreationContext context)
		{
			object instance = base.Instantiate(context);

			Marshal(instance, Model);

			return instance;
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:8,代码来源:RemoteMarshallerActivator.cs

示例15: CanResolve

 public bool CanResolve(CreationContext context, ISubDependencyResolver parentResolver,
                        ComponentModel model,
                        DependencyModel dependency)
 {
     return dependency.TargetType != null &&
            dependency.TargetType.IsArray &&
            dependency.TargetType.GetElementType().IsInterface;
 }
开发者ID:bertusmagnus,项目名称:Sutekishop,代码行数:8,代码来源:ArrayResolver.cs


注:本文中的Castle.MicroKernel.CreationContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。