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)); }
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)); }
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; }
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; }
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 }
public T TryResolve <T>() { return(container.TryResolve <T>()); }
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>(); }
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); }