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 388 posts 1360 karma points
    Mar 18, 2019 @ 20:41
    Marcio Goularte
    1

    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 6163 posts 24143 karma points MVP 8x admin c-trib
    Mar 26, 2019 @ 09:30
    Alex Skrypnyk
    0

    Hi Marcio

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

    Thanks,

    Alex

  • Marcio Goularte 388 posts 1360 karma points
    Apr 01, 2019 @ 00:02
    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 767 posts 2273 karma points c-trib
    Apr 01, 2019 @ 15:36
    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.

  • Leon Lindeberg 12 posts 103 karma points
    Oct 08, 2020 @ 12:33
    Leon Lindeberg
    0

    Did you make progress on this? Is there a GitHub issue?

  • Andy Felton 185 posts 484 karma points c-trib
    Mar 08, 2022 @ 16:10
    Andy Felton
    0

    Just wondering did anybody achieve this?

Please Sign in or register to post replies

Write your reply to:

Draft