public void Does_not_throw_when_registering_null_dependency()
        {
            var container = new Funq.Container();

            container.Register((IFoo) new Foo());
            Assert.That(container.TryResolve <IFoo>() != null);
            container.Register((IFoo)null);
            Assert.That(container.TryResolve <IFoo>() == null);
        }
Ejemplo n.º 2
0
        public override void Configure(Funq.Container container)
        {
            //Set JSON web services to return idiomatic JSON camelCase properties
            ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;

            Plugins.Add(new SwaggerFeature());

            //Register all your dependencies:
            DependencyConfig.ResolveDependencies(container);

            //Enable Authentication an Registration
            AuthConfig.ConfigureAuth(Plugins, container);

            //Configure Custom User Defined REST Paths for your services
            RouteConfig.ConfigureServiceRoutes(Routes);

            //Change the default ServiceStack configuration
            //const Feature disableFeatures = Feature.Jsv | Feature.Soap;
            SetConfig(new EndpointHostConfig
            {
                //EnableFeatures = Feature.All.Remove(disableFeatures),
                AppendUtf8CharsetOnContentTypes = new HashSet <string> {
                    ContentType.Html
                },
                DebugMode = true, //Show StackTraces in service responses during development
            });

            //Set MVC to use the same Funq IOC as ServiceStack
            ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
            ServiceStackController.CatchAllController = reqCtx => container.TryResolve <HomeController>();
        }
Ejemplo n.º 3
0
        public override void Configure(Funq.Container container)
        {
            //Set JSON web services to return idiomatic JSON camelCase properties
            ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;

            //Load environment config from text file if exists
            var liveSettings = "~/appsettings.txt".MapHostAbsolutePath();
            var appSettings  = File.Exists(liveSettings)
                ? (IAppSettings) new TextFileSettings(liveSettings)
                : new AppSettings();

            AppConfig = new AppConfig(appSettings);
            container.Register(AppConfig);

            //Change the default ServiceStack configuration
            //const Feature disableFeatures = Feature.Jsv | Feature.Soap;
            SetConfig(new HostConfig
            {
                AppendUtf8CharsetOnContentTypes = new HashSet <string> {
                    MimeTypes.Html
                },
                HandlerFactoryPath = "api",
                DebugMode          = true,
            });

            Plugins.Add(new MiniProfilerFeature());

            //Register a external dependency-free
            container.Register <ICacheClient>(new MemoryCacheClient());
            //Configure an alt. distributed persistent cache that survives AppDomain restarts. e.g Redis
            //container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("localhost:6379"));

            //Enable Authentication an Registration
            ConfigureAuth(container, appSettings);

            //Create your own custom User table
            using (var db = container.Resolve <IDbConnectionFactory>().Open())
                db.DropAndCreateTable <User>();

            //Register application services
            container.Register(new TodoRepository());
            container.Register <ITwitterGateway>(new TwitterGateway());

            //Configure Custom User Defined REST Paths for your services
            ConfigureServiceRoutes();

            Plugins.Add(new SwaggerFeature {
                UseBootstrapTheme = true
            });
            Plugins.Add(new PostmanFeature());
            Plugins.Add(new CorsFeature());

            //Set MVC to use the same Funq IOC as ServiceStack
            ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
            ServiceStackController.CatchAllController = reqCtx => container.TryResolve <HomeController>();
        }
Ejemplo n.º 4
0
        public override void Configure(Funq.Container container)
        {
            //Set JSON web services to return idiomatic JSON camelCase properties
            ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;

            //Register Typed Config some services might need to access
            var appSettings = new AppSettings();

            AppConfig = new AppConfig(appSettings);
            container.Register(AppConfig);

            //Register all your dependencies:

            //Register a external dependency-free
            container.Register <ICacheClient>(new MemoryCacheClient());
            //Configure an alt. distributed persistent cache that survives AppDomain restarts. e.g Redis
            //container.Register<IRedisClientsManager>(c => new PooledRedisClientManager("localhost:6379"));

            //Enable Authentication an Registration
            ConfigureAuth(container);

            //Create your own custom User table
            var dbFactory = container.Resolve <IDbConnectionFactory>();

            dbFactory.Run(db => db.DropAndCreateTable <User>());

            //Register application services
            container.Register(new TodoRepository());
            container.Register <ITwitterGateway>(new TwitterGateway());

            //Configure Custom User Defined REST Paths for your services
            ConfigureServiceRoutes();

            //Change the default ServiceStack configuration
            //const Feature disableFeatures = Feature.Jsv | Feature.Soap;
            SetConfig(new EndpointHostConfig {
                //EnableFeatures = Feature.All.Remove(disableFeatures),
                AppendUtf8CharsetOnContentTypes = new HashSet <string> {
                    ContentType.Html
                },
            });

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

            //Set MVC to use the same Funq IOC as ServiceStack
            ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));
            ServiceStackController.CatchAllController = reqCtx => container.TryResolve <HomeController>();
        }