Caliburn笔记-依赖注入容器(wpf框架)
发布时间:2020-05-23 05:02:21 所属栏目:程序设计 来源:互联网
导读:参考与此http://caliburn.codeplex.com/wikipage?title=Auto-Registering%20ComponentsreferringTitle=Documentation 此为基础,看了没用,不看不行…了解下注册流程. 注册组件,差不多离不开这几种模式 手动注册 元数据标签注册 外部dll加载注册 1.内置服务则用
|
参考与此http://caliburn.codeplex.com/wikipage?title=Auto-Registering%20Components&referringTitle=Documentation 此为基础,看了没用,不看不行…了解下注册流程.
1.内置服务则用手动注册. 2.挂元数据标签,如下 [PerRequest(typeof(IHomePresenter))]
public class HomePresenter : Presenter,IHomePresenter
{
}
3.外部dll加载 重写CaliburnApplication的SelectAssemblies方法 protected override System.Reflection.Assembly[] SelectAssemblies()
{
return new[] { Assembly.GetEntryAssembly(),typeof(Caliburn.WPF.ApplicationFramework.Bind).Assembly};
}
private void InspectAssembly(Assembly assembly,ICollection<ComponentInfo> componentList,ICollection<Type> configs)
{
var types = assembly.GetExportedTypes();
foreach (var type in types)
{
foreach (var attribute in type.GetCustomAttributes(true).OfType<RegisterAttribute>())
componentList.Add(attribute.GetComponentInfo(type));
}
foreach (var type in types)
{
if(_configType.IsAssignableFrom(type) && !type.IsAbstract)
configs.Add(type);
}
}
内置服务+自定义服务注册好以后,接下来的任务就是注册实例.即组件的生命周期状况.内置都为Singleton /// <summary>
/// The lifetime of a Caliburn component.
/// </summary>
public enum ComponentLifetime
{
/// <summary>
/// One instance per application.
/// </summary>
Singleton,/// <summary>
/// A new instance is created on each request.
/// </summary>
PerRequest,/// <summary>
/// A new instance is created per custom lifetime rules.
/// </summary>
Custom
}
新版本可能会更新,所以不去研究它了 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
