Closed rebeccapowell closed 9 years ago
You should check out MediatR.. ShortBus works fine, but MediatR is actively maintained
Thanks. I've made the realisation that the Shortbus Nuget package is way out of date with the current source.
I did actually figure this out, if anyone else asks. The IoC config looks likes this:
public static void RegisterDependencies()
{
IContainer container = BuildContainer();
// set MVC resolver
System.Web.Mvc.DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
// set Shortbus resolver! Important :-)
ShortBus.DependencyResolver.SetResolver(new ShortBus.Autofac.AutofacDependencyResolver(container));
}
public static IContainer BuildContainer()
{
var builder = new ContainerBuilder();
// MVC registrations
builder.RegisterModelBinders(Assembly.GetExecutingAssembly());
builder.RegisterModelBinderProvider();
builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired();
builder.RegisterFilterProvider();
builder.RegisterSource(new ContravariantRegistrationSource());
builder.RegisterAssemblyTypes(typeof(IMediator).Assembly, typeof(IMyHandler).Assembly)
.AsClosedTypesOf(typeof(IRequestHandler<,>))
.AsImplementedInterfaces();
builder.RegisterType<Mediator>().AsImplementedInterfaces().InstancePerLifetimeScope();
builder.RegisterType<ShortBus.Autofac.AutofacDependencyResolver>()
.AsImplementedInterfaces()
.InstancePerLifetimeScope();
builder.RegisterType<MyDbContext>().As<IMyDbContext>().InstancePerRequest();
return builder.Build();
}
If was simply that I hadn't twigged that there were two AutofacDependencyResolvers,. one in the Autofac.MVC5 package and one in the Shortbus package. Once that clicked, it all fell into place.
I'll take a look at that other project. Would be nice to have a nuget source instead of a local build.
You can do install-package shortbus -pre
for the latest
On Fri, Jul 3, 2015 at 9:32 AM, Ben Powell notifications@github.com wrote:
Thanks. I've made the realisation that the Shortbus Nuget package is way out of date with the current source.
I did actually figure this out, if anyone else asks. The IoC config looks likes this:
public static void RegisterDependencies() { IContainer container = BuildContainer();
// set MVC resolver System.Web.Mvc.DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); // set Shortbus resolver! Important :-) ShortBus.DependencyResolver.SetResolver(new ShortBus.Autofac.AutofacDependencyResolver(container));
}
public static IContainer BuildContainer() { var builder = new ContainerBuilder();
// MVC registrations builder.RegisterModelBinders(Assembly.GetExecutingAssembly()); builder.RegisterModelBinderProvider(); builder.RegisterControllers(Assembly.GetExecutingAssembly()).PropertiesAutowired(); builder.RegisterFilterProvider(); builder.RegisterSource(new ContravariantRegistrationSource()); builder.RegisterAssemblyTypes(typeof(IMediator).Assembly, typeof(IMyHandler).Assembly) .AsClosedTypesOf(typeof(IRequestHandler<,>)) .AsImplementedInterfaces(); builder.RegisterType<Mediator>().AsImplementedInterfaces().InstancePerLifetimeScope(); builder.RegisterType<ShortBus.Autofac.AutofacDependencyResolver>() .AsImplementedInterfaces() .InstancePerLifetimeScope(); builder.RegisterType<MyDbContext>().As<IMyDbContext>().InstancePerRequest(); return builder.Build();
}
If was simply that I hadn't twigged that there were two AutofacDependencyResolvers,. one in the Autofac.MVC5 package and one in the Shortbus package. Once that clicked, it all fell into place.
I'll take a look at that other project. Would be nice to have a nuget source instead of a local build.
— Reply to this email directly or view it on GitHub https://github.com/mhinze/ShortBus/issues/41#issuecomment-118364300.
I've had some troubles with StructureMap, so I decided to try Autofac instead:
Global.ascx.cs
IoCConfig.cs
In my controller I then have:
And the error returned by index is:
It appears to be trying to resolve
StructureMap.IContainer
, but I have set the DependencyResolver to use Autofac.Does anyone have any ideas on how to solve this? I love the idea of Shortbus, but I'm having a lot of problems getting up and running. Does anyone have an example Github ASP.NET MVC project they can direct me to?