Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register configurations from document type class #983

Open
bradyclifford opened this issue Aug 29, 2016 · 2 comments
Open

Register configurations from document type class #983

bradyclifford opened this issue Aug 29, 2016 · 2 comments

Comments

@bradyclifford
Copy link

Add ability to register indexes, foreign keys, grants, other document mapping needs, etc. for a document type from within the document type class using a static method called ConfigurePersistence(MartenRegistry).

If FubuMVC.Marten sees that in a document type, call it before creating the DocumentStore.

public class DocumentTypeExample
{

   public Guid Id { get; set; }
   public string FirstName { get; set; }
   public int AssigneeId { get; set; }
   public int Number { get; set; }

   public static void ConfigurePersistence(MartenRegistry registry) 
   {
        registry.MappingFor(this).DatabaseSchemaName = "other";        
        registry.For(this).ForeignKey<User>(x => x.AssigneeId);
        registry.For(this).GinIndexJsonData();

        registry.For<User>().Duplicate(x => x.FirstName, configure:idx =>
        {
            idx.IndexName = "idx_special";
            idx.Method = IndexMethod.hash;
        });

        registry.For(this).Index(x => x.Number, x =>
        {
            x.Method = IndexMethod.brin;
            x.Casing = ComputedIndex.Casings.Lower;
            x.IndexName = "mt_my_name";
            x.IsConcurrent = true;
            x.IsUnique = true;
            x.Where = "(data ->> 'Number')::int > 10";
        });

   }

}
@bradyclifford
Copy link
Author

Maybe the Attributes better serve this purpose?

@jeremydmiller
Copy link
Member

I went for a public static ConfigureMarten(DocumentMapping) convention on DocumentMapping classes here. If we want to do more discovery via type scanning, I'd rather build that out into FubuMVC.Marten where we can use the more efficient StructureMap type scanning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants