luktom.net
  • blog
  • contact
  • polish





Nancy and StructureMap

On 14 Nov, 2015
C#
No Comments
Views : 6007

Nancy provides her own IoC container – TinyIoC, but sometimes you need to use something more powerfull – like e.g. StuctureMap.

Integration of Nancy and SturctureMap is quite easy (as everything in Nancy :). We start with NuGet package installation:

Install-Package Nancy.Bootstrappers.StrucutreMap

And the, we need to create custom bootstrapper (or modify existing if there is one already in your project), which inherits from StructureMapNancyBootstrapper:

public class Bootstrapper : StructureMapNancyBootstrapper
{
  protected override void ConfigureApplicationContainer(IContainer container)
  {
    container.Configure(x =>
    {
      x.Scan(y => y.Assembly(Assembly.GetCallingAssembly()));

      x.For<IService>().Use<MyService>();
    });
  }
}

In our custom bootstrapper we overload ConfigureApplicationContainer method, in which we can access to container instance used by Nancy. This is a perfect place to configure container and register dependencies.



Tags :   c#

Leave a Comment

Click here to cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>





Łukasz Tomaszkiewicz

Łukasz Tomaszkiewicz

Łukasz Tomaszkiewicz is a highly skilled and passionate cloud expert who loves to automate repeatable things and secure them.

His broad experience in the areas of software development, database design, containerization and cloud infrastructure management gives him a holistic view of a modern technology stack.

In his spare time he enjoys photography, blogging and speaking on local IT-related communities.

Vim-believer :)

Categories

  • Ansible
  • AWS
  • C#
  • Go
  • Google Cloud
  • Kubernetes
  • Prometheus
  • Speeches
  • Virtualization
  • Windows

Tags

alert alerting alertmanager ansible ansible operator argocd aws aws cli aws ug bash c# centos cloudwatch databases esxi flux gcp gitops google cloud k8s kubernetes linux mysql open source operator operator-sdk policies powershell prelekcje prometheus recovery restore rhel rpo rto scp speeches terraform virtualization vmware vsan vsphere weaveworks wifi windows

Copyright © 2006-2018 by Łukasz Tomaszkiewicz. Wszelkie prawa zastrzeżone