我正在尝试使用structuremap来正确创建我的控制器,我正在使用DI将一个INewsService注入一个NewsController,这是我唯一的构造函数.
public class NewsController : Controller
{
private readonly INewsService newsService;
public NewsController(INewsService newsService)
{
this.newsService = newsService;
}
public ActionResult List()
{
var newsArticles = newsService.GetNews();
return View(newsArticles);
}
}
Run Code Online (Sandbox Code Playgroud)
我正在使用此代码启动应用程序
public class Application : HttpApplication
{
protected void Application_Start()
{
RegisterIoC();
RegisterViewEngine(ViewEngines.Engines);
RegisterRoutes(RouteTable.Routes);
}
public static void RegisterIoC()
{
ObjectFactory.Initialize(config => {
config.UseDefaultStructureMapConfigFile = false;
config.AddRegistry<PersistenceRegistry>();
config.AddRegistry<DomainRegistry>();
config.AddRegistry<ControllerRegistry>();
});
DependencyResolver.InitializeWith(new StructureMapDependencyResolver());
ControllerBuilder.Current.SetControllerFactory(typeof(IoCControllerFactory));
}
}
Run Code Online (Sandbox Code Playgroud)
但Structuremap似乎不想注入INewsService,我得到错误没有为此对象定义无参数构造函数.
我错过了什么?
我有一个前端带有 angular 的 Spring Boot 应用程序。
我在 html5 模式下使用 ui-router,我希望 spring 在所有未知路由上呈现相同的 index.html。
// Works great, but it also overrides all the resources
@RequestMapping
public String index() {
return "index";
}
// Seems do be the same as above, but still overrides the resources
@RequestMapping("/**")
public String index() {
return "index";
}
// Works well but not for subdirectories. since it doesn't map to those
@RequestMapping("/*")
public String index() {
return "index";
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是我怎样才能创建一个回退映射但允许通过资源?
我无法理解为什么我不能引用scala枚举类型.
问题是有时我可以引用枚举:
enum(UserStatus)
Run Code Online (Sandbox Code Playgroud)
有时它抱怨无法找到枚举
not found: type UserStatus
Run Code Online (Sandbox Code Playgroud)
为什么我有时不能引用Enumeration类?
枚举的生成源似乎没问题,并且它与我生活在同一个地方的另一个枚举很有效,相同的用法......
有什么建议?
生成的枚举源是:
public final class models.UserStatus extends java.lang.Object{
public static final scala.Enumeration$Value Busy();
public static final scala.Enumeration$Value Free();
public static final scala.Enumeration$ValueSet$ ValueSet();
public static final scala.Enumeration$Value withName(java.lang.String);
public static final scala.Enumeration$Value apply(int);
public static final int maxId();
public static final scala.Enumeration$ValueSet values();
public static final java.lang.String toString();
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试为play framework 2.0实现一个枚举映射器
def enumFormat[E <: Enumeration](enum: E): Formatter[E#Value] = new Formatter[E#Value] {
def bind(key: String, data: Map[String, String]) = …Run Code Online (Sandbox Code Playgroud) 在Play2的zentasks示例中,我们有了方法
def isAuthenticated(f: => String => Request[AnyContent] => Result) = {
Security.Authenticated(username, onUnauthorized) { user =>
Action(request => f(user)(request))
}
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是添加另一种方法,如果我想直接从数据库中获取用户,我可以使用它.
在所有方法中添加包装器会有点无聊
def method() = isAuthenticated { username => implicit request =>
UserDAO.findOneByEmail(username).map { user =>
Ok(html.user.view(user))
}.getOrElse(Forbidden)
}
Run Code Online (Sandbox Code Playgroud)
我是函数式编程的新手,所有这些=>让我头晕目眩:)
有什么建议?