QuickstartΒΆ

If you are starting a new project, you will want to download the Jabberwocky packages from the Velir Nuget feed.

If you haven’t yet set that up, you’ll want to go to Visual Studio -> Tools -> Options -> NuGet Package Manager -> Package Sources

Then you’ll want to add ‘http://nuget.velir.com/nuget‘ as a feed (you can also name the feed ‘Velir’).

If you’re starting a new MVC project, you can start by just including the Jabberwocky.Glass.Autofac.Mvc package into your website project. If you’re not using MVC, you can include the Jabberwocky.Glass.Autofac project instead.

You will also want to pull in the Glass.Mapper.Sc package. This will allow you to setup your Glass Models and configure the attribute loader in the GlassMapperScCustom.cs file.

Note

For instructions on setting up Glass.Mapper, refer to the guide here.

Notice that in either case, we’re going to assume you’ll be using the common stack of Glass.Mapper and Autofac.

The first thing that you’ll want to do is create a new folder in the root of your Website project, called ‘App_Start’. In this folder, you’ll want to create a new class, called AutofacConfig.

You can use the following as a template:

public class AutofacConfig
{
	public static void Start()
	{
		var builder = new ContainerBuilder();

		builder.RegisterGlassServices();
		builder.RegisterCacheServices();
		builder.RegisterProcessors(Assembly.Load("YOURPROJECT.Library"));
		builder.RegisterGlassMvcServices("YOURPROJECT.Web");
		builder.RegisterGlassFactory("YOURPROJECT.Library");
		builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
		builder.RegisterControllers(Assembly.GetExecutingAssembly());

		// Module registrations
		builder.RegisterModule(new MiniProfilerModule("YOURPROJECT.Library", "YOURPROJECT.Web"));
		builder.RegisterModule(new LogInjectionModule<ILog>(LogManager.GetLogger);

		// Custom Registrations

		// This is necessary to 'seal' the container, and make it resolvable from the AutofacStartup.ServiceLocator singleton
		IContainer container = builder.Build();
		container.RegisterContainer();

		// Create the dependency resolver.
		var resolver = new AutofacWebApiDependencyResolver(container);

		// Configure Web API with the dependency resolver.
		GlobalConfiguration.Configuration.DependencyResolver = resolver;

		// Configure the MVC dependency resolver
		DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
	}
}

Note

If you are going to use the MiniProfilerModule like in the sample above, you will also need to include the Jabberwocky.Autofac.Extras.MiniProfiler nuget package.