• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MicroKernel.CreationContext类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Castle.MicroKernel.CreationContext的典型用法代码示例。如果您正苦于以下问题:C# CreationContext类的具体用法?C# CreationContext怎么用?C# CreationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CreationContext类属于Castle.MicroKernel命名空间,在下文中一共展示了CreationContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: Create

        public override object Create(CreationContext context, Type type)
        {
            var types = new List<Type>(_extraInterfaces.Length + 1);
              types.Add(type);
              types.AddRange(_extraInterfaces);

              return MockFactory.GenerateDynamicMock(types.ToArray());
        }
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:8,代码来源:MultiMockingStrategy.cs


示例17: Instantiate

		protected override object Instantiate(CreationContext context)
		{
			String url = (String) Model.ExtendedProperties["remoting.uri"];

			// return Activator.GetObject(Model.Service, url);

			return RemotingServices.Connect( Model.Service, url );
		}
开发者ID:nats,项目名称:castle-1.0.3-mono,代码行数:8,代码来源:RemoteActivator.cs


示例18: CreateInstance

        protected override object CreateInstance(CreationContext context, object[] arguments, System.Type[] signature)
        {
            // TODO: Support interceptors + copy "use fast create instance" logic from DefaultComponentActivator

            // Support internal and private constructors
            return Activator.CreateInstance(Model.Implementation,
                                            BindingFlags.CreateInstance | BindingFlags.NonPublic | BindingFlags.Public |
                                            BindingFlags.Instance, null, arguments, null, null);
        }
开发者ID:JackWangCUMT,项目名称:rhino-tools,代码行数:9,代码来源:AutoMockingComponentActivator.cs


示例19: Resolve

        public override object Resolve(CreationContext context)
        {
            // Retrieve from Session, or if not found, resolve via container.
            object result = HttpContext.Current.Session[uniqueKey];

            if (result == null)
                result = HttpContext.Current.Session[uniqueKey] = base.Resolve(context);

            return result;
        }
开发者ID:MikeAnderson,项目名称:mongoDB-NoRM-sample-blog,代码行数:10,代码来源:PerSessionLifestyle.cs


示例20: Instantiate

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

			object behavior = ProxyUtil.GetUnproxiedInstance(instance);
			WcfExtensionScope scope = WcfUtils.GetScope(Model);
			WcfUtils.ExtendBehavior(Kernel, scope, behavior);

			return instance;
		}
开发者ID:kkozmic,项目名称:Castle.Facilities.Wcf,代码行数:10,代码来源:WcfBehaviorActivator.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MicroKernel.DefaultKernel类代码示例发布时间:2022-05-24
下一篇:
C# Interceptors.LogInvocationInterceptor类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap