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


C# Container.TryResolve方法代码示例

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


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

示例1: Does_TryResolve_from_delegate_cache

        public void Does_TryResolve_from_delegate_cache()
        {
            var container = new Container();
            container.Register(c => new Foo { Id = 1 });

            var instance = (Foo)container.TryResolve(typeof(Foo));
            Assert.That(instance.Id, Is.EqualTo(1));

            instance = (Foo)container.TryResolve(typeof(Foo));
            Assert.That(instance.Id, Is.EqualTo(1));
        }
开发者ID:AVee,项目名称:ServiceStack,代码行数:11,代码来源:ContainerTests.cs

示例2: ConfigureDatabase

 private void ConfigureDatabase(Container container)
 {
     // find all the DTOs we will be storing and ensure the tables exist
     var dtos = TableAttribute.GetTableClasses(typeof(Player).Assembly).Cast<System.Type>().ToArray();
     var db = container.TryResolve<IDbConnectionFactory>();
     db.Run(x => x.CreateTableIfNotExists(dtos));
 }
开发者ID:jokecamp,项目名称:OpenFootballApi,代码行数:7,代码来源:ApiAppHost.cs

示例3: Factory

 public static ISomeService Factory(Container c)
 {
     // Register the service by type...
     c.RegisterAutoWiredType(typeof(SomeService), ReuseScope.Hierarchy);
     // ... and force auto-wiring to happen.
     ISomeService result = (ISomeService)c.TryResolve(typeof(SomeService));
     return result;
 }
开发者ID:ServiceStack,项目名称:ServiceStack,代码行数:8,代码来源:ContainerChildTests.cs

示例4: Configure

        public override void Configure(Container container)
        {
            var repositoryConnectionString = ConfigurationManager.ConnectionStrings["Repositories"].ConnectionString ?? string.Empty;
            FunqBindings.Configure(container);
            //Rather than reference web and owin stuff in bindings dll, we bind IAuditService here as the references are availible in the web project
            container.Register<IAuditService>(c => new AuditService(c.Resolve<IConfigurationService>(), HttpContext.Current.GetOwinContext().Authentication, repositoryConnectionString)).ReusedWithin(ReuseScope.Request);

            ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
            ServiceStackController.CatchAllController = reqCtx => container.TryResolve<TestController>();
            JsConfig.DateHandler = JsonDateHandler.ISO8601;
        }
开发者ID:parrymike,项目名称:myMDS_Dev,代码行数:11,代码来源:ServiceStackConfig.cs

示例5: Configure

        public override void Configure(Container container)
        {
            SetConfig(new EndpointHostConfig
                          {
                              GlobalResponseHeaders =
                                  {
                                      {"Access-Control-Allow-Origin", "*"},
                                      {"Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS "},
                                      {
                                          "Access-Control-Allow-Headers",
                                          "X-Requested-With , origin, content-type, accept"
                                      },
                                      {"Access-Control-Allow-Credentials", "true"}
                                  },
                          });

            JsConfig.EmitCamelCaseNames = false;

            var local = new NHibernateHelper(NHibernateHelper.TipoServidor.MySqlServer, "localhost", "csunifytd",
                                             "cygnisoft", "8adyl6do", "false", new[] {"UnifyModels"});

            container.Register(session => local.GetCurrentSession()).ReusedWithin(ReuseScope.Container);
            container.Register(rp => new RpArticulo(container.TryResolve<ISession>()));
            container.Register(rp => new RpArticuloFoto(container.TryResolve<ISession>()));
            container.Register(rp => new RpArticuloDeposito(container.TryResolve<ISession>(), "Remoto", "Remota"));
            container.Register(rp => new RpDeposito(container.TryResolve<ISession>()));
            container.Register(rp => new RpEmpresa(container.TryResolve<ISession>()));
            container.Register(rp => new RpEntidad(container.TryResolve<ISession>()));
            container.Register(rp => new RpImpuesto(container.TryResolve<ISession>()));
            container.Register(rp => new RpSeguridadGo(container.TryResolve<ISession>()));
            container.Register(rp => new RpRevision(container.TryResolve<ISession>()));
            container.Register(rp => new RpTomaInventario(container.TryResolve<ISession>()));
            container.Register(rp => new RpTraslado(container.TryResolve<ISession>()));

            Plugins.Add(new CorsFeature()); //Registers global CORS Headers
        }
开发者ID:rafareyes7,项目名称:UnifyWS,代码行数:36,代码来源:AppHost.cs

示例6: Configure

        public override void Configure(Container container)
        {
            //Register Typed Config some services might need to access
            var appSettings = new AppSettings();
            AppConfig = new AppConfig(appSettings);
            container.Register(AppConfig);

            //NLog
            container.Register(x => new NLogFactory());
            //Elmah
            container.Register(x => new ElmahLogFactory(container.Resolve<NLogFactory>()));
            LogManager.LogFactory = container.Resolve<ElmahLogFactory>();
            container.Register<ILog>(x => LogManager.GetLogger(GetType()));

            //Cache
            container.Register<ICacheClientExtended>(new MemoryCacheClientExtended());

            //Plugins.Add(new RazorFormat());

            container.Register<IDbConnectionFactory>(new OrmLiteConnectionFactory(AppConfig.ConnectionString, false, SqlServerDialect.Provider));
            ConfigureAuth(container);

            //Register all repositories
            container.Register<IDBSetupRepository>(c => new DBSetupRepository { _db = c.Resolve<IDbConnectionFactory>() });
            container.Register<IGalleryRepository>(c => new GalleryRepository { _db = c.Resolve<IDbConnectionFactory>() });
            container.Register<IUserRepository>(c => new UserRepository { _db = c.Resolve<IDbConnectionFactory>() });
            container.Register<IPhotoRepository>(c => new PhotoRepository { _db = c.Resolve<IDbConnectionFactory>() });

            //Setup database
            SetupDatabase(container);

            //Register services
            container.Register<IBaseService>(c => new BaseService
                {
                    UserRepo = c.Resolve<IUserRepository>(),
                    Cacher = c.Resolve<ICacheClientExtended>(),
                    Logger = c.Resolve<ILog>(),
                    AppConfig = c.Resolve<AppConfig>()
                });

            container.Register<IImageProcessingService>(c => new ImageProcessingService());

            container.Register<IUserService>(c => new UserService() {_baseService = c.Resolve<IBaseService>()});

            container.Register<IPhotoService>(c => new PhotoService
                {
                    _baseService = c.Resolve<IBaseService>(),
                    _photoRepo = c.Resolve<IPhotoRepository>(),
                    ImageProcessingService = c.Resolve<IImageProcessingService>(),
                    AppConfig = c.Resolve<AppConfig>(),
                    UserService = c.Resolve<IUserService>()
                });

            container.Register<IGalleryService>(c => new GalleryService
            {
                _baseService = c.Resolve<IBaseService>(),
                _galleryRepo = c.Resolve<IGalleryRepository>(),
                PhotoService = c.Resolve<IPhotoService>(),
                UserService = c.Resolve<IUserService>()
            });

            ConfigureServiceRoutes();

            Plugins.Add(new SwaggerFeature());
            Plugins.Add(new CorsFeature());

            /*
            SetConfig(new EndpointHostConfig {
                CustomHttpHandlers = {
                    { HttpStatusCode.NotFound, new RazorHandler("/notfound") },
                    { HttpStatusCode.Unauthorized, new RazorHandler("/login") },
                }
            });
            */

            PhotoExtension.PhotoService = container.Resolve<IPhotoService>();

            //Set MVC to use the same Funq IOC as ServiceStack
            ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
            ServiceStackController.CatchAllController = reqCtx => container.TryResolve<HomeController>();
        }
开发者ID:senseicz,项目名称:UniPhotogallery,代码行数:81,代码来源:AppHost.cs

示例7: Configure

        public override void Configure(Container container)
        {
            container.Adapter = containerAdapter;
            #if DEBUG

            container.Register<ICacheClient>(c => new MemoryCacheClient());

            #else

            container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("localhost:30705"));
            container.Register(c => c.Resolve<IRedisClientsManager>().GetCacheClient()).ReusedWithin(ReuseScope.None);
            #endif

            Plugins.Add(new RazorFormat());

            container.Register<IDbConnectionFactory>(
                new OrmLiteConnectionFactory(
                    @"Server=127.0.0.1;Port=5432;Database=PlayitForward;User Id=postgres;Password=swordfish;", PostgreSqlDialect.Provider));

            using (var db = container.Resolve<IDbConnectionFactory>().OpenDbConnection())
            {
                db.CreateTable<App>();
                db.CreateTable<Sub>();
                db.CreateTable<User>();
                db.CreateTable<Giveaway>();
                db.CreateTable<Entry>();
                db.CreateTable<Message>();
                db.CreateTable<ModLog>();
            }

            container.RegisterAutoWired<GiveawayService>();
            container.RegisterAutoWired<UserService>();
            container.RegisterAutoWired<SecureUserService>();
            container.RegisterAutoWired<GamesService>();

            SetConfig(
                new HostConfig
                {
                    //CustomHttpHandlers =
                    //{
                    //    { HttpStatusCode.NotFound, new RazorHandler("/404") },
                    //    { HttpStatusCode.Unauthorized, new RazorHandler("/login") },
                    //},
                    GlobalResponseHeaders =
                    {
                        { "Access-Control-Allow-Origin", "*" },
                        { "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" },
                    },
                    EnableFeatures = Feature.All.Remove(GetDisabledFeatures()),
                });

            var appSettings = new AppSettings();
            Plugins.Add(new RazorFormat());
            Plugins.Add(
                new AuthFeature(
                    () => new SteamUserSession(),
                    new IAuthProvider[] { new SteamOpenIdOAuthProvider(appSettings) }));
            Plugins.Add(new SessionFeature());

            ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
            ServiceStackController.CatchAllController = reqCtx => container.TryResolve<HomeController>();
            //log.InfoFormat("AppHost Configured: {0}", DateTime.Now);
        }
开发者ID:robertbaker,项目名称:PlayItForward,代码行数:63,代码来源:AppHost.cs


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