//
// Summary:
// Register a type mapping with the container.
//
// Parameters:
// container:
// Container to configure.
//
// injectionMembers:
// Injection configuration objects.
//
// Type parameters:
// TFrom:
// System.Type that will be requested.
//
// TTo:
// System.Type that will actually be returned.
//
// Returns:
// The Microsoft.Practices.Unity.UnityContainer object that this method was called
// on (this in C#, Me in Visual Basic).
//
// Remarks:
// This method is used to tell the container that when asked for type TFrom, actually
// return an instance of type TTo. This is very useful for getting instances of
// interfaces.
// This overload registers a default mapping and transient lifetime.
[SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "As designed")]
public static IUnityContainer RegisterType<TFrom, TTo>(this IUnityContainer container, params InjectionMember[] injectionMembers) where TTo : TFrom;

class Program
{
static UnityContainer container = new UnityContainer();

static void Init()
{
container.RegisterType<IPlayer, Player>();
container.RegisterType<IMediaFile, MediaFile>();
}
static void Main(string[] args)
{
Init();
OperationMain op1 = container.Resolve<OperationMain>();
op1.PlayMedia();
Console.ReadLine();
}
}

//媒体文件
public interface IMediaFile
{
string FilePath { get; set; }
}

//默认媒体文件
public class MediaFile : IMediaFile
{
private string filePath;
public string FilePath
{
get
{
return filePath;
}
set
{
filePath = value;
}
}
}

//播放器
public interface IPlayer
{
void Play(IMediaFile file);
}

//默认播放器
public class Player : IPlayer
{
public void Play(IMediaFile file)
{
Console.WriteLine(file.FilePath);
}
}

public class OperationMain
{
IMediaFile _mtype;
IPlayer _player;

public OperationMain(IPlayer player,IMediaFile mtype)
{
_player = player;
_mtype = mtype;
}

public void PlayMedia()
{
_player.Play(_mtype);
}
}

最新文章

  1. web.config配置
  2. [lintcode 14] First Position of Target
  3. NavBarControl
  4. 使用豆瓣的pypi源
  5. 【leetcode】Binary Search Tree Iterator
  6. 使用haproxy做负载均衡时保持客户端真实的IP
  7. xcode 4 安装cocos2d-x 2.1.4
  8. linux之utime函数解析
  9. Atitit.Gui控件and面板----数据库区-mssql 2008 权限 配置 报表查看成员
  10. python运维开发(二十二)---JSONP、瀑布流、组合搜索、多级评论、tornado框架简介
  11. WCF不支持 ASP.NET 兼容性 解决办法
  12. Kafka 源代码分析之LogManager
  13. C++STL之String
  14. SpriteBuilder中粒子发射器的reset on visibility toggle选项解释
  15. #Java学习之路——基础阶段二(第四篇)
  16. winform datagridview 导出excel
  17. 安装xgboost
  18. Puppet日常总结
  19. 正向选择(positive selection)、中性选择(neutral selection)、平衡选择(balancing selection)示意图
  20. Android开发工程师文集-1 小时学会各种Drawable

热门文章

  1. 你见过的最全面的 Python 重点
  2. Vue-nodeJS环境搭建
  3. LinuxShell脚本——认识Shell脚本
  4. Java入门——编写并运行第一个程序
  5. springcloud vue 微服务分布式 activiti工作流 前后分离 集成代码生成器 shiro权限
  6. 微信小程序初体验遇到的坑
  7. 微信小程序底部导航栏(tabbar)
  8. Day_02
  9. Java jdom解析xml文件带冒号的属性
  10. 密度峰值聚类算法MATLAB程序