public void Build(IFunctionHostBuilder builder)
 {
     builder
     .CompilerOptions(options => options
                      .HttpTarget(CompileTargetEnum.AspNetCore) // the magic!
                                                                //.OutputSourceTo(@"/Users/jamesrandall/code/authoredSource")
                      )
     .Authorization(auth => auth
                    .AuthorizationDefault(AuthorizationTypeEnum.TokenValidation)
                    .AddOpenIdConnectTokenValidator("https://accidentalfish.eu.auth0.com/.well-known/openid-configuration")
                    )
     .OpenApiEndpoint(openApi => openApi
                      .Title("My API")
                      .Version("0.0.0")
                      .UserInterface()
                      )
     .Setup((sc, r) =>
     {
         sc.AddSingleton <IRepository, Repository>();
         r.Discover <FunctionAppConfiguration>();
     })
     .Functions(functions => functions
                .HttpRoute("todo", route => route
                           .HttpFunction <CreateTodoItemCommand>(HttpMethod.Post)
                           .HttpFunction <GetAllTodoItemsQuery>(HttpMethod.Get)
                           .HttpFunction <MarkCompleteCommand>(HttpMethod.Put)
                           )
                .HttpRoute("loaderio-fa4864b7cff0c92b67ffdc6c1b85d9a5", route => route
                           .HttpFunction <LoaderIoQuery>(HttpMethod.Get).Options(options => options.ResponseHandler <StringContentResponseHandler>())
                           )
                );
 }
Exemplo n.º 2
0
 public static IFunctionHostBuilder UseMediatR(this IFunctionHostBuilder builder)
 {
     builder
         .CompilerOptions(options =>options
             .MediatorTypeSafetyEnforcer<MediatRTypeSafetyEnforcer>()
             .MediatorResultTypeExtractor<MediatRResultTypeExtractor>()
         )
         .Mediator<MediatRDecorator>();
     return builder;
 }
 public void Build(IFunctionHostBuilder builder)
 {
     builder
     .CompilerOptions(options => options
                      .OutputSourceTo(@"/Users/jamesrandall/code/authoredSource")
                      )
     .Setup((serviceCollection, commandRegistry) =>
     {
         serviceCollection.AddValidatorsFromAssembly(typeof(FunctionAppConfiguration).Assembly);
         commandRegistry.Discover(typeof(FunctionAppConfiguration).Assembly);
     })
     .OpenApiEndpoint(openApi => openApi
                      .Title("My API Title 2.0.0-beta-113")
                      .Version("v2")
                      .UserInterface()
                      .AddValidatorsFromAssembly(typeof(FunctionAppConfiguration).Assembly)
                      .AddXmlComments(Path.Combine(Path.GetDirectoryName(typeof(FunctionAppConfiguration).Assembly.Location), "OpenApi.xml"))
                      )
     .AddFluentValidation()
     .Functions(functions =>
     {
         functions.RegisterCustomers();
     });
 }
        public void Build(IFunctionHostBuilder builder)
        {
            builder
            .CompilerOptions(options => options
                             .OutputSourceTo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "authoredSource"))
                             )
            .Setup((serviceCollection, commandRegistry) =>
            {
                serviceCollection.AddValidatorsFromAssembly(typeof(FunctionAppConfiguration).Assembly);
                commandRegistry.Discover(typeof(FunctionAppConfiguration).Assembly);
            })
            .OpenApiEndpoint(openApi => openApi
                             .AddOpenApiInfo("v2-internal", "internal/openapi.yaml", new OpenApiInfo
            {
                Title       = "API intern 2.0.0-beta-113",
                Version     = "v2",
                Description = "Upcoming API"
            }
                                             )
                             .AddOpenApiInfo("v2-external", "external/openapi.yaml", new OpenApiInfo
            {
                Title       = "API 2.0.0-beta-113",
                Version     = "v2",
                Description = "Upcoming API"
            },
                                             new CustomOpenApiHttpFunctionFilter(),
                                             true
                                             )

                             // OpenApi
                             .UserInterface()
                             //.InjectStylesheet(Assembly.GetExecutingAssembly(), "Resources.OpenApi.theme-material.css")
                             //.InjectResource(Assembly.GetExecutingAssembly(), "Resources.OpenApi.testlogo.svg")
                             //.InjectResources(Assembly.GetExecutingAssembly(), "Resources.OpenApi.diagrams")
                             .InjectLogo(Assembly.GetExecutingAssembly(), "Resources.OpenApi.testlogo.svg")
                             .InjectJavaScript(Assembly.GetExecutingAssembly(), "Resources.OpenApi.console-log.js")


                             // ReDoc
                             .ReDocUserInterface()
                             //.ReDocInjectStylesheet(Assembly.GetExecutingAssembly(), "Resources.ReDoc.theme-material.css")
                             //.ReDocInjectResource(Assembly.GetExecutingAssembly(), "Resources.ReDoc.testlogo.svg")
                             .ReDocInjectResources(Assembly.GetExecutingAssembly(), "Resources.ReDoc.diagrams")
                             .ReDocInjectExtensions(Assembly.GetExecutingAssembly(), "Resources.ReDoc.extensions", "external/openapi.yaml")
                             .ReDocInjectTags(Assembly.GetExecutingAssembly(), "Resources.ReDoc.tags", "external/openapi.yaml")
                             .ReDocInjectLogo(Assembly.GetExecutingAssembly(), "Resources.ReDoc.testlogo.svg")
                             //.ReDocInjectJavaScript(Assembly.GetExecutingAssembly(), "Resources.ReDoc.console-log.js")
                             .ReDocAddDocumentFilter(() => new CustomReDocDocumentFilter())

                             .AddValidatorsFromAssembly(typeof(FunctionAppConfiguration).Assembly)
                             .AddXmlComments(Path.Combine(Path.GetDirectoryName(typeof(FunctionAppConfiguration).Assembly.Location), "OpenApi.xml"))
                             .AddSecurityScheme("Bearer", // Reference.Id of this security scheme
                                                new OpenApiSecurityScheme
            {
                Description = "JWT Authorization header using the Bearer scheme.",
                Type        = SecuritySchemeType.Http, // We set the scheme type to http since we're using bearer authentication
                Scheme      = "bearer"                 // The name of the HTTP Authorization scheme to be used in the Authorization header. In this case "bearer".
            })
                             )
            .AddFluentValidation()
            .Functions(functions =>
            {
                functions.RegisterCustomers();
            });
        }
        public void Build(IFunctionHostBuilder builder)
        {
            builder
            .CompilerOptions(options => options
                             .OutputSourceTo(@"/Users/jamesrandall/code/authoredSource")
                             )
            .Setup((serviceCollection, commandRegistry) =>
            {
                commandRegistry.Register <HelloWorldCommandHandler>();
                commandRegistry.Register <AddCommandHandler>();
                commandRegistry.Register <CosmosCommandHandler>();
                commandRegistry.Register <CosmosDocumentCommandHandler>();
                commandRegistry.Register <CosmosDocumentBatchCommandHandler>();

                serviceCollection.AddTransient <IMessageProvider, MessageProvider>();

                serviceCollection.AddLogging();
            })
            .OpenApiEndpoint(openApi => openApi
                             .Title("A Simple API")
                             .Version("0.0.0")
                             .UserInterface()
                             )
            .Functions(functions => functions
                       .HttpRoute("/HelloWorld", route => route
                                  .HttpFunction <HelloWorldCommand>(AuthorizationTypeEnum.Anonymous, HttpMethod.Post)
                                  .OpenApiDescription("Says hello world")
                                  .Options(options => options
                                           .AddHeaderMapping(x => x.HeaderName, "x-header-name")
                                           .ResponseHandler <CustomResponseHandler>()
                                           )
                                  )

                       /*.HttpRoute("/Form", route => route
                        *   .HttpFunction<FormCommand>(HttpMethod.Post)
                        * )
                        * .OpenApiDescription("A route description")
                        * //.CosmosDb("CosmosConnection", cosmos => cosmos
                        *   //.ChangeFeedFunction<CosmosCommand, ExampleCosmosErrorHandler>("Items", "ToDoList", leaseCollectionPrefix:"fn1")//, convertToPascalCase:true)
                        *   //.ChangeFeedFunction<CosmosDocumentCommand>("Items", "ToDoList")
                        *   //.ChangeFeedFunction<CosmosDocumentBatchCommand>("Items", "ToDoList", leaseCollectionPrefix:"fn2")
                        * //)
                        * .HttpRoute("/Add", route => route
                        *   .HttpFunction<AddCommand>(AuthorizationTypeEnum.Anonymous,HttpMethod.Post)
                        *   .OpenApiDescription("Adds two numbers together")
                        *   .OpenApiResponse(400, "Some sort of error")
                        *   //.Serializer<DefaultCaseJsonSerializer>()
                        *   .Options(options => options
                        *       .JsonNamingStrategies<DefaultNamingStrategy, SnakeCaseNamingStrategy>()
                        *   )
                        * )
                        * /*.OpenApiName("HelloWorld")*/
                       //.Timer<HelloWorldCommand, HelloWorldTimerCommandFactory>("*/5 * * * * *")

                       /*.Storage("StorageConnectionString", storage => storage
                        *  .QueueFunction<HelloWorldCommand>("myqueue")
                        * )
                        * .ServiceBus("ServiceBusConnectionString", sb => sb
                        *  .QueueFunction<HelloWorldCommand>("myqueue")
                        * .SubscriptionFunction<HelloWorldCommand>("mytopic", "mysub")
                        * )*/
                       );
        }