Esempio n. 1
0
        private static void ApplyDefaultConfiguration(PiccoloConfiguration configuration)
        {
            configuration.RequestHandlerFactory = new DefaultRequestHandlerFactory();
            configuration.ParameterBinders      = new Dictionary <Type, IParameterBinder>
            {
                { typeof(String), new StringParameterBinder() },
                { typeof(Boolean), new BooleanParameterBinder() },
                { typeof(Boolean?), new NullableBooleanParameterBinder() },
                { typeof(Byte), new ByteParameterBinder() },
                { typeof(Byte?), new NullableByteParameterBinder() },
                { typeof(Int16), new Int16ParameterBinder() },
                { typeof(Int16?), new NullableInt16ParameterBinder() },
                { typeof(Int32), new Int32ParameterBinder() },
                { typeof(Int32?), new NullableInt32ParameterBinder() },
                { typeof(DateTime), new DateTimeParameterBinder() },
                { typeof(DateTime?), new NullableDateTimeParameterBinder() }
            };
            configuration.JsonSerialiser = model =>
            {
                var jsonSerializerSettings = new JsonSerializerSettings();
                jsonSerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();

                return(JsonConvert.SerializeObject(model, jsonSerializerSettings));
            };
            configuration.JsonDeserialiser = (type, payload) => JsonConvert.DeserializeObject(payload, type);
        }
Esempio n. 2
0
        private static void DiscoverEventHandlers(PiccoloConfiguration configuration, Assembly assembly)
        {
            var requestProcessingHandlers = EventHandlerScanner.FindEventHandlersForEvent <RequestProcessingEvent>(assembly);
            var requestFaultedHandlers    = EventHandlerScanner.FindEventHandlersForEvent <RequestFaultedEvent>(assembly);
            var requestProcessedHandlers  = EventHandlerScanner.FindEventHandlersForEvent <RequestProcessedEvent>(assembly);

            configuration.EventHandlers = new EventHandlers(requestProcessingHandlers, requestFaultedHandlers, requestProcessedHandlers);
        }
Esempio n. 3
0
        private static void RunStartupTasks(PiccoloConfiguration configuration, Assembly assembly)
        {
            var bootstrapperTypes = assembly.GetTypesImplementing <IStartupTask>();

            foreach (var bootstrapperType in bootstrapperTypes)
            {
                var instance = (IStartupTask)Activator.CreateInstance(bootstrapperType);
                instance.Run(configuration);
            }
        }
Esempio n. 4
0
        private static void RunStartupTasks(PiccoloConfiguration configuration, Assembly assembly)
        {
            var bootstrapperTypes = assembly.GetExportedTypes().Where(x => x.GetInterfaces().Contains(typeof(IStartupTask)));

            foreach (var bootstrapperType in bootstrapperTypes)
            {
                var instance = (IStartupTask)Activator.CreateInstance(bootstrapperType);
                instance.Run(configuration);
            }
        }
Esempio n. 5
0
        private static void DiscoverEventHandlers(PiccoloConfiguration configuration, Assembly assembly)
        {
            configuration.EventHandlers = new EventHandlers();

            var requestProcessingEventHandlers = assembly.GetExportedTypes().Where(x => x.GetInterfaces().Contains(typeof(IHandle <RequestProcessingEvent>)));

            configuration.EventHandlers.RequestProcessing = requestProcessingEventHandlers.ToList();

            var requestProcessedEventHandlers = assembly.GetExportedTypes().Where(x => x.GetInterfaces().Contains(typeof(IHandle <RequestProcessedEvent>)));

            configuration.EventHandlers.RequestProcessed = requestProcessedEventHandlers.ToList();

            var requestFaultedEventHandlers = assembly.GetExportedTypes().Where(x => x.GetInterfaces().Contains(typeof(IHandle <RequestFaultedEvent>)));

            configuration.EventHandlers.RequestFaulted = requestFaultedEventHandlers.ToList();
        }
Esempio n. 6
0
        public static PiccoloConfiguration ApplyConfiguration(Assembly assembly, bool applyCustomConfiguration)
        {
            if (AutomaticAssemblyDetectionFailed(assembly))
            {
                throw new InvalidOperationException(ExceptionMessageBuilder.BuildMissingGlobalAsaxMessage());
            }

            var configuration = new PiccoloConfiguration();

            DiscoverRequestHandlers(configuration, assembly);
            ApplyDefaultConfiguration(configuration);

            if (applyCustomConfiguration)
            {
                RunStartupTasks(configuration, assembly);
            }

            return(configuration);
        }
Esempio n. 7
0
        private static void ApplyDefaultConfiguration(PiccoloConfiguration configuration)
        {
            configuration.ObjectFactory = new DefaultObjectFactory();
            configuration.Parsers       = new Dictionary <Type, Func <string, object> >
            {
                { typeof(String), x => x },
                { typeof(Boolean), x => Boolean.Parse(x) },
                { typeof(Boolean?), x => Boolean.Parse(x) },
                { typeof(Int32), x => Int32.Parse(x) },
                { typeof(Int32?), x => Int32.Parse(x) },
                { typeof(DateTime), x => DateTime.Parse(x) },
                { typeof(DateTime?), x => DateTime.Parse(x) }
            };
            configuration.JsonSerialiser = model =>
            {
                var jsonSerializerSettings = new JsonSerializerSettings
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                };

                return(JsonConvert.SerializeObject(model, jsonSerializerSettings));
            };
            configuration.JsonDeserialiser = (type, payload) => JsonConvert.DeserializeObject(payload, type);
        }
Esempio n. 8
0
        private static void DiscoverRequestHandlers(PiccoloConfiguration configuration, Assembly assembly)
        {
            var requestHandlers = assembly.GetTypesImplementing <IRequestHandler>();

            configuration.RequestHandlers = new ReadOnlyCollection <Type>(requestHandlers);
        }
Esempio n. 9
0
        private static void DiscoverRequestHandlers(PiccoloConfiguration configuration, Assembly assembly)
        {
            var requestHandlers = assembly.GetExportedTypes().Where(x => x.GetInterfaces().Contains(typeof(IRequestHandler)));

            configuration.RequestHandlers = new ReadOnlyCollection <Type>(requestHandlers.ToList());
        }