StructureMap项目地址:http://structuremap.sourceforge.net/Default.htm

我以webform为例,简单介绍一下如何在项目中使用StructureMap:

1.在Global.asax中的Application_Start事件中添加如下代码,主要用于初始化StructureMap的容器

 ObjectFactory.Initialize(
                x =>
                {
                    x.IgnoreStructureMapConfig = true;
                    x.For<Ants.Provider.IAuthenticateProvider>().Singleton().Use<Ants.Provider.SessionAuthenticateProvider>();
                    x.For<Ants.Provider.ICacheProvider>().Singleton().Use(p => Ants.Provider.CacheFactory.Instance());
                }
                );

 

2.如何使用

StructureMap.ObjectFactory.GetInstance<Ants.Provider.IAuthenticateProvider>()

更多使用方法参考:http://www.docin.com/p-74984655.html

http://www.cnblogs.com/RicCC/archive/2010/04/01/structuremap-demo.html

相关文章:

  • 2021-09-04
  • 2021-09-21
  • 2022-12-23
  • 2022-12-23
  • 2021-09-21
  • 2022-01-02
猜你喜欢
  • 2021-12-27
  • 2021-05-27
  • 2021-08-29
  • 2022-02-24
  • 2022-02-13
相关资源
相似解决方案