Exemple #1
0
        static void Main()
        {
            Func <IFoo> getFoo              = () => new DummyFoo();
            var         module              = new CommandModule(getFoo);
            var         resolver            = new CommandHandlerResolver(module);
            var         commandMediaTypeMap = new CommandMediaTypeMap(new CommandMediaTypeWithQualifierVersionFormatter())
            {
                // Use a string to decouple command name from the command clr type. This will ensure
                // refactoring, i.e. moving CommandThatHasASyncHandler or renaming it, won't change your http API.
                { "CommandThatHasASyncHandler", typeof(CommandThatHasASyncHandler) },

                // Can use typeof().Name if you are not concerned with backwards compat or versioning.
                { typeof(CommandThatHasAnAsyncHandler).Name, typeof(CommandThatHasAnAsyncHandler) },
            };
            var settings = new CommandHandlingSettings(resolver, commandMediaTypeMap);
            var commandHandlingMiddleware = CommandHandlingMiddleware.HandleCommands(settings);

            // 5. Add the middleware to your owin pipeline
            using (WebApp.Start("http://localhost:8080",
                                app =>
            {
                app.Use(commandHandlingMiddleware);
            }))
            {
                Console.WriteLine("Press any key");
            }
        }
        static void Main()
        {
            Func<IFoo> getFoo = () => new DummyFoo();
            var module = new CommandModule(getFoo);
            var resolver = new CommandHandlerResolver(module);
            var commandMediaTypeMap = new CommandMediaTypeMap(new CommandMediaTypeWithQualifierVersionFormatter())
            {
                // Use a string to decouple command name from the command clr type. This will ensure 
                // refactoring, i.e. moving CommandThatHasASyncHandler or renaming it, won't change your http API. 
                { "CommandThatHasASyncHandler", typeof(CommandThatHasASyncHandler) }, 

                // Can use typeof().Name if you are not concerned with backwards compat or versioning.
                { typeof(CommandThatHasAnAsyncHandler).Name, typeof(CommandThatHasAnAsyncHandler) },
            };
            var settings = new CommandHandlingSettings(resolver, commandMediaTypeMap);
            var commandHandlingMiddleware = CommandHandlingMiddleware.HandleCommands(settings);

            // 5. Add the middleware to your owin pipeline
            using(WebApp.Start("http://localhost:8080",
                app =>
                {
                    app.Use(commandHandlingMiddleware);
                }))
            {
                Console.WriteLine("Press any key");
            }
        }