Ejemplo n.º 1
0
        private static Marten.DocumentStore CreateNewStore(string connString, DocumentMappableSerializationBinder serializationBinder,
                                                           IDocumentStoreAssemblyDiscoverer discoverer)
        {
            var store = Marten.DocumentStore.For(options =>
            {
                options.Logger(new SerilogMartenLogger());

                var serializer = new Marten.Services.JsonNetSerializer
                {
                    EnumStorage = EnumStorage.AsString
                };

                serializer.Customize(x => x.SerializationBinder = serializationBinder);

                options.PLV8Enabled = false; // Not installed by default in PostgreSQL 11

                options.AutoCreateSchemaObjects = AutoCreate.None;

                options.Connection(connString);

                options.Serializer(serializer);

                foreach (var(docType, attr) in discoverer.DiscoverAutoDocumentCollectionTypes())
                {
                    options.Storage.MappingFor(docType);
                }

                foreach (var cfgType in discoverer.DiscoverDocumentStoreConfigurers())
                {
                    ((IDocumentStoreConfiguration)Activator.CreateInstance(cfgType)).Configure(options);
                }
            });

            return(store);
        }
Ejemplo n.º 2
0
        public void customize_json_net_serialization()
        {
            // SAMPLE: customize_json_net_serialization
            var serializer = new Marten.Services.JsonNetSerializer();

            // To change the enum storage policy to store Enum's as strings:
            serializer.EnumStorage = EnumStorage.AsString;

            // All other customizations:
            serializer.Customize(_ =>
            {
                // Code directly against a Newtonsoft.Json JsonSerializer
                _.DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
                _.ConstructorHandling  = ConstructorHandling.AllowNonPublicDefaultConstructor;
            });

            var store = DocumentStore.For(_ =>
            {
                _.Connection("some connection string");

                // Replace the default JsonNetSerializer with the one we configured
                // above
                _.Serializer(serializer);
            });
            // ENDSAMPLE
        }
        public void customize_json_net_serialization()
        {
            // SAMPLE: customize_json_net_serialization
    var serializer = new Marten.Services.JsonNetSerializer();
            
    // To change the enum storage policy to store Enum's as strings:
    serializer.EnumStorage = EnumStorage.AsString;

    // All other customizations:
    serializer.Customize(_ =>
    {
        // Code directly against a Newtonsoft.Json JsonSerializer
        _.DateTimeZoneHandling = DateTimeZoneHandling.RoundtripKind;
        _.ConstructorHandling = ConstructorHandling.AllowNonPublicDefaultConstructor;
    });

    var store = DocumentStore.For(_ =>
    {
        _.Connection("some connection string");

        // Replace the default JsonNetSerializer with the one we configured
        // above
        _.Serializer(serializer);
    });
            // ENDSAMPLE
        }