首先在非web 的project 里添加注册解析路由服务的代码:

// 我再web 里面添加后编译通过 ,运行出错,原因尚未找到

builder = new ContainerBuilder();
var container = builder.Build();
_container = container;

//we create new instance of ContainerBuilder
//because Build() or Update() method can only be called once on a ContainerBuilder.

//dependencies
builder = new ContainerBuilder();
builder.RegisterType<RoutePublisher>().As<IRoutePublisher>().SingleInstance();
builder.Update(container);
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

 然后 在global 里进行注册路由

public void RegisterRoutes(RouteCollection route) {
var Containe = new ContainerManager();
RouteConfig.RegisterRoutes(route);
//var routes = RouteTable.Routes;
var scope = Containe.Container.BeginLifetimeScope();
var routePublisher = Containe.Resolve<IRoutePublisher>("", scope);
routePublisher.RegisterRoutes(route);
}

 

路由就会在RouteTable.Routes 里出现

posted on 2018-06-04 16:03  死生之外,皆是闲事  阅读(1071)  评论(0编辑  收藏  举报