本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}