Пример #1
0
        private static Thing ConfigureThing <T>(IServiceProvider provider)
            where T : Thing
        {
            var thing       = provider.GetRequiredService <T>();
            var option      = provider.GetRequiredService <ThingOption>();
            var optionsJson = new JsonSerializerOptions
            {
                WriteIndented        = false,
                IgnoreNullValues     = true,
                PropertyNamingPolicy = JsonNamingPolicy.CamelCase
            };

            var converter  = new ConverterInterceptorFactory(thing, optionsJson);
            var properties = new PropertiesInterceptFactory(thing, option);
            var events     = new EventInterceptFactory(thing, option);
            var actions    = new ActionInterceptFactory(option);

            CodeGeneratorFactory.Generate(thing, new List <IInterceptorFactory>()
            {
                converter,
                properties,
                events,
                actions
            });

            thing.ThingContext = new Context(converter.Create(),
                                             properties.Create(),
                                             events.Events,
                                             actions.Actions);
            return(thing);
        }
 public ConverterInterceptorTest()
 {
     _fixture = new Fixture();
     _thing   = new LampThing();
     _factory = new ConverterInterceptorFactory(_thing, new JsonSerializerOptions
     {
         PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
         IgnoreNullValues     = true,
     });
 }