davezych / shience

A .NET port(ish) of Github's Scientist library. (https://github.com/github/scientist)
MIT License
9 stars 1 forks source link

Implement Database publisher #10

Closed davezych closed 8 years ago

davezych commented 8 years ago

Implement publisher for databases.

Things to consider:

MovGP0 commented 8 years ago

you can use EntityFramework CodeFirst to create the tables for you. The user should provide the database provider and connection strings. This way you are database agnostic.

You just need an initializer:

public class MyDbContext : DbContext 
{
    public IDbSet<Foo> Foos { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        Database.SetInitializer(new MyDbContextInitializer());

        base.OnModelCreating(modelBuilder);
    }
}

public class MyDbContextInitializer : DropCreateDatabaseIfModelChanges<MyDbContext>
{
    protected override void Seed(MyDbContext dbContext)
    {
        // seed data

        base.Seed(dbContext);
    }
} 

source: Entity Framework 4.1 Code First not creating tables

MovGP0 commented 8 years ago

Note: because this has external dependencies, it should be put into an external library.

MovGP0 commented 8 years ago

another thing: we might not want to ship a database provider, because the user probably has its own database scheme that he wants to use. usually, the user would just provide an adapter method to his logging facility (ie. NLog, Serilog, etc.).

This way, the developer/administrator can configure where the output should go to by setting an appropriate logging appender.

davezych commented 8 years ago

16 might negate this entirely. Let the user provide a function and they deal with it as they please.

davezych commented 8 years ago

@MovGP0 should we remove IPublisher and SetPublisher and just use the New<TResult>([NotNull]string name, [NotNull]Action<ExperimentResult<TResult>> publish) overload? The more I think about it, the more I don't see a need for a global publisher. Passing in a lambda is easy, and for more complicated publishing passing a static method works great, such as:

static void MyPublish(ExperimentResult<bool> result)
{
    //whatever
}

var science = Shience.New<bool>("test", MyPublish);

This also avoids having to implement various publishers, since users can easily specify their own.

MovGP0 commented 8 years ago

yes, I agree with that. The user should provide his own publisher logic. It would also solve some issues with thread safety and unit testing.

davezych commented 8 years ago

:+1: I'll close this and open a new issue to track removing SetPublisher.