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


C# IContainer.TryGetInstance方法代码示例

本文整理汇总了C#中IContainer.TryGetInstance方法的典型用法代码示例。如果您正苦于以下问题:C# IContainer.TryGetInstance方法的具体用法?C# IContainer.TryGetInstance怎么用?C# IContainer.TryGetInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IContainer的用法示例。


在下文中一共展示了IContainer.TryGetInstance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnUpdatePageModel

        protected virtual void OnUpdatePageModel(IContainer container)
        {
            //global
            IAssetService assetSvc = container.GetInstance<IAssetService>();
            assetSvc.UpdatePageModel(this);

            //page
            IPage page = container.TryGetInstance<IPage>(PageName);
            if (page != null)
            {
                if (ParentName == null) ParentName = page.Parent;
                IPage parent = container.TryGetInstance<IPage>(ParentName);
                if (parent != null) parent.UpdatePageModel(this);
                page.UpdatePageModel(this);
            }

            //using the page name, find width and template using scope fallback rules
            var pages = Service.GetServicePages(Scope, PageName, ParentName);

            var pageWidth = pages.Where(p => p.Width != null).LastOrDefault();
            if (pageWidth != null) PageWidth = pageWidth.Width;
            var pageTemplate = pages.Where(p => p.Template != null).LastOrDefault();
            if (pageTemplate != null) PageTemplate = pageTemplate.Template;

            var includes = Service.GetIncludes(Scope, PageName, ParentName);

            //let each widget update page model
            foreach (Include include in includes)
            {
                var w = container.TryGetInstance<IWidget>(include.Name);
                if (w != null) w.UpdatePageModel(this, include);
            }
        }
开发者ID:erikzaadi,项目名称:atomsitethemes.erikzaadi.com,代码行数:33,代码来源:PageModel.cs

示例2: ConfigureAutoMapper

 private static void ConfigureAutoMapper(IContainer container)
 {
     var configuration = container.TryGetInstance<IConfiguration>();
     if (configuration == null) return;
     //saying AutoMapper how to resolve services
     configuration.ConstructServicesUsing(container.GetInstance);
     foreach (var profile in container.GetAllInstances<Profile>())
     {
         configuration.AddProfile(profile);
     }
 }
开发者ID:rabbal,项目名称:AspNetMVCNTierTemp,代码行数:11,代码来源:ProjectObjectFactory.cs

示例3: Validate

        /// <summary>
        /// Gets whether the controller is valid for the execution
        /// </summary>
        /// <param name="dependencyContainer">Dependency container to check for feature registry</param>
        /// <param name="filterContext">Action context for the request</param>
        /// <returns>True if the controller feature is vaild for this controller, false otherwise</returns>
        public override bool Validate(IContainer dependencyContainer, ActionExecutingContext filterContext)
        {
            Ensure.Argument.NotNull(dependencyContainer, "dependencyContainer");

            var registry = dependencyContainer.TryGetInstance<IFeatureRegistry>();

            // if the feature path is empty, the feature path is equal to
            // the Controller/Action path
            if (!this.FeaturePath.Any())
            {
                this.FeaturePath = new[]
                {
                    filterContext.ActionDescriptor.ControllerDescriptor.ControllerName.Without("Controller"),
                    filterContext.ActionDescriptor.ActionName
                };
            }

            return registry == null || registry.IsEnabled(this.FeaturePath);
        }
开发者ID:shibbard,项目名称:Multi-tenancy-Sample,代码行数:25,代码来源:FeatureAttribute.cs


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