Skip to content

Latest commit

 

History

History
58 lines (44 loc) · 1.31 KB

README.md

File metadata and controls

58 lines (44 loc) · 1.31 KB

FluentBootstrapPolicy

Execute pre-checks before running your application!

Build status

Define policies

public class MyAppPolicyConfiguration : AbstractPolicyConfiguration
{
    public MyAppPolicyConfiguration(IServiceLocator serviceLocator)
        : base(serviceLocator)
    {
        Check<ICurrencyProvider>(provider =>
        {
           //do sth
            return false;
        });

        Check<IStorageClient>(client =>
        {
            return client.CheckAccessControl();
        });
    }
}

Init policy context

IFluentBootstrap _policies;

ContainerBuilder builder = new ContainerBuilder();

builder.RegisterType<StorageClient>().As<IStorageClient>().SingleInstance();
builder.RegisterType<CurrencyProvider>().As<ICurrencyProvider>().SingleInstance();
builder
       .RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
       .AssignableTo<AbstractPolicyConfiguration>()
       .As<AbstractPolicyConfiguration>();

var container = builder.Build();
_policies = FluentBootstrap.Instance;

_policies.Configure(ctx =>
{
    ctx.Use(new AutofacServiceLocator(container));
});

Execute policies

  _policies.Execute();

@ziλasal