Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marcio Goularte 319 posts 1073 karma points
    Mar 18, 2019 @ 20:41
    Marcio Goularte
    0

    NPoco Fluent Mappings and Performing operations during Poco events with Umbraco 8

    I use NPoco a lot of time and always set up the Pocos using fluent mappings. This mapping runs in DatabaseFactory:

    public void Application_Start()
    {
        MyFactory.Setup();
    }
    public static class MyFactory
    {
        public static DatabaseFactory DbFactory { get; set; }
    
        public static void Setup()
        {
            var fluentConfig = FluentMappingConfiguration.Configure(new OurMappings());
            //or individual mappings
            //var fluentConfig = FluentMappingConfiguration.Configure(new UserMapping(), ....);
    
            DbFactory = DatabaseFactory.Config(x =>
            {
                x.UsingDatabase(() => new Database("connString"));
                x.WithFluentConfig(fluentConfig);
                x.WithMapper(new Mapper());
            });
        }
    }
    

    https://github.com/schotime/NPoco/wiki/Fluent-Mappings-including-Conventional

    Also how is it possible to use interceptors.

    https://github.com/schotime/NPoco/wiki/Performing-Operations-during-Poco-events-(Insert,-Update,-etc)

    How would that be at Umbraco?

    I made a few attempts using IUserComposer but all failed

  • Alex Skrypnyk 5176 posts 18866 karma points MVP 2x admin c-trib
    27 days ago
    Alex Skrypnyk
    0

    Hi Marcio

    Did you find a solution? Can you share with our community?

    Thanks,

    Alex

  • Marcio Goularte 319 posts 1073 karma points
    21 days ago
    Marcio Goularte
    0

    Hi Alex,

    I have not found a solution yet without having to modify the Umbraco code. I'm doing some testing. The problem to create the mappings is to create at the time of UmbracoDatabase Setup. I got to making modifications to the source code. I'm seeing a way to do this after the setup or I'll open a PR with the solution I did by changing the source code.

    I modify this part of code https://github.com/umbraco/Umbraco-CMS/blob/853087a75044b814df458457dc9a1f778cc89749/src/Umbraco.Core/Persistence/UmbracoDatabaseFactory.cs#L216

  • Stephen 750 posts 2198 karma points hq
    21 days ago
    Stephen
    0

    Briefly looked at our code in UmbracoDatabaseFactory and indeed it does not really support adding more mappers and / more tweaking the configuration.

    I'm totally fine with extending it so that we make it more open.

    I am not entirely sure what is the best way to do it, though. Maybe make our own UmbracoDatabaseFactory class public with some virtual extension points, would allow ppl to subclass it - but the factory is not resolved via the normal composers concept, because it needs to be resolved way earlier in the boot process. It is created by CoreRuntime.GetDatabaseFactory so ppl would have to also override the runtime, which means overriding the application base (in global.asax)... not so simple.

    Happy to hear about other ideas.

Please Sign in or register to post replies

Write your reply to:

Draft