NancyFx 2.0的开源框架的使用-AspnetBootstrapping
新建一个空的Web项目AspnetBootstrappingDemo
然后添加NuGet组件
- Nancy
- Nancy.Hosting.Aspnet
- Nancy.ViewEngines.Razor
继续往项目里面添加Module,Views,Models文件夹,然而先写Models文件夹里面的类,往Models文件夹添加 RatPack类
public string FirstName { get; set; }
再往Models文件夹里面添加RatPackWithDependencyText类,并让它继承RatPack
public string ApplicationDependencyText { get; set; }
public string RequestDependencyText { get; set; }
再往Models文件夹里添加IApplicationDependency类
string GetContent();
再往Models文件夹里面添加IRequestDependency类
string GetContent();
再往Models文件夹里面添加ApplicationDependency类
private readonly DateTime currentDateTime;
/// <summary>
/// 初始化 RequestDependencyClass 类的新实例
/// </summary>
public ApplicationDependency()
{
this.currentDateTime = DateTime.Now;
}
public string GetContent()
{
return "这是一个应用程序级依赖项, 构建在:" + this.currentDateTime.ToLongTimeString();
}
继续往Models文件夹里面添加RequestDependency类
private readonly DateTime currentDateTime;
/// <summary>
/// 初始化 RequestDependency 类的新实例
/// </summary>
public RequestDependency()
{
this.currentDateTime = DateTime.Now;
}
public string GetContent()
{
return "这是按请求的依赖项, 构造于:" + this.currentDateTime.ToLongTimeString();
}
然后往Module文件夹里面添加DependencyModule类
private readonly IApplicationDependency applicationDependency;
private readonly IRequestDependency requestDependency;
public DependencyModule(IApplicationDependency applicationDependency,IRequestDependency requestDependency)
{
this.applicationDependency = applicationDependency;
this.requestDependency = requestDependency;
Get("/",Lexan=>
{
var model = new RatPackWithDependencyText
{
FirstName="Lexan",
ApplicationDependencyText=this.applicationDependency.GetContent(),
RequestDependencyText=this.requestDependency.GetContent()
};
return View["razor-dependency",model];
});
}
继续往根目录下添加Bootstrapper类
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
//base.ConfigureApplicationContainer(container); //将应用程序依赖项注册为普通的单一实例
container.Register<IApplicationDependency,ApplicationDependency>().AsSingleton();
//将每个请求的依赖项注册为每个请求的单一实例
container.Register<IRequestDependency,RequestDependency>().AsPerRequestSingleton();
}
然后往Views文件夹里面添加razor-dependency页面
<!DOCTYPE html> <html>
<head>
<meta name="viewport" content="width=device-width" />
<title>剃刀视图引擎Demo</title>
</head>
<body>
<div>
<h1>你好,@Model.FirstName</h1>
<p>这是一个剃刀的页面</p>
<p>@Model.ApplicationDependencyText</p>
<p>@Model.RequestDependencyText</p>
</div>
</body>
</html>
最后修改Web.config文件
<httpHandlers>
<add verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
</httpHandlers>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<validation validateIntegratedModeConfiguration="false" />
<handlers>
<add name="Nancy" verb="*" type="Nancy.Hosting.Aspnet.NancyHttpRequestHandler" path="*" />
</handlers>
</system.webServer>
运行看看界面如何
好了,今天的博文到此结束,明天同一时间更新博文,期待你的关注,谢谢!
NancyFx 2.0的开源框架的使用-AspnetBootstrapping的更多相关文章
- NancyFx 2.0的开源框架的使用-Basic
这是NancyFx开源框架中的Basic认证,学习一下! 首先当然是新建一个空的Web,BasicDemo 继续在项目中添加Nuget包,记得安装的Nuget包是最新的预发行版 Nancy Nancy ...
- NancyFx 2.0的开源框架的使用-CustomModule(自定义模块)
NancyFx框架的自定义模块 新建一个空的Web项目 然后通过NuGet库安装下面的包 Nancy Nancy.Hosting.Aspnet 然后添加Models,Module,Views三个文件夹 ...
- NancyFx 2.0的开源框架的使用-ModelBinding(实现绑定)
NancyFx框架中使用绑定模型 新建一个空的Web程序 然后安装Nuget库里面的包 Nancy Nancy.Hosting.Aspnet Nancy.ViewEnglines.Spark 并在We ...
- NancyFx 2.0的开源框架的使用-HosingOwin
Nancy框架的Owin使用 先建一个空的Web项目 然后往Nuget库里面添加Nancy包 Nancy Nancy.Owin Nancy.ViewEnglines.Spark 然后添加Models, ...
- NancyFx 2.0的开源框架的使用-Authentication
新建一个空的项目 新建好了空的项目以后,接着通过NuGet安装一下三个包 Nancy Nancy.Hosting.Aspnet Nancy.ViewEnglines.Razor 然后在项目中添加Mod ...
- NancyFx 2.0的开源框架的使用-Forms
同样的像前面2篇博文一样,每个项目的开始基本都是建个空的Web项目 在NuGet库中安装以下几个NuGet包 Nancy Nancy.Authentication.Forms Nancy.Hostin ...
- NancyFx 2.0的开源框架的使用-Stateless
同样和前面一样新建一个空的Web项目,都在根目录添加Module,Models,Views文件夹 添加Nuget包 在Models文件夹里面添加UserModel类 public string Use ...
- NancyFx 2.0的开源框架的使用-Stateless(二)
继续上一篇Stateless的博文,在上一篇的博文的基础上稍微加点东西 接下来右键解决方案添加新项目,一样建一个空的Web项目 然后在StatelessDemoWeb项目里面添加Views文件夹,Sc ...
- NancyFx 2.0的开源框架的使用-Caching
新建一个空的Web项目,命名CachingDemo 然后添加三个Nuget安装包 Nancy Nancy.Hosting.Aspnet Nancy.ViewsEngines.Razor 然后往项目里面 ...
随机推荐
- unity插件开发——一个例子:简单的svn集成
在unity开发过程中,通常我们习惯性地在Windows操作系统下使用svn进行版本管理,而每次提交更新,都需要回到文件夹下的这种操作让人无法忍受.是不是可以集成svn到unity中呢?查了一圈uni ...
- xlrd的使用详细介绍以及基于Excel数据参数化实例详解
1.安装xlrd xlrd是python用于读取excel的第三方扩展包,所以在使用xlrd前,需要使用以下命令来安装xlrd.pip install xlrd 在使用这个命令之前先确定自己有没有安装 ...
- Linux云自动化运维第八课
第十三单元 软件安装 一.软件名称识别 [abrt-addon-ccpp]-[2.1.11-19].[el7].[x86_64].rpm ###rpm结尾的适用与redhat操作系统 || ...
- [android] 手机卫士黑名单功能(ListView结合SQLite增删改)
修改界面,在顶部横条上增加一个添加按钮,点击打开一个自定义对话框,输入电话号码和拦截模式保存到数据库 自定义对话框看这篇http://www.cnblogs.com/taoshihan/p/53703 ...
- java集合基础
集合概念与作用 1现实生活中把很多事物凑在一起就是集合.java中的集合类:是一种工具,就像是容器,存储任意数量的有共同属性的对象. 2在类的内部,对数据进行组织: 简单而快速的搜索大数量的条目 有的 ...
- Java Script 字符串操作
JS中常用几种字符串操作: big() small() bold() fontcolor() fontsize() italics() strike() link() charAt() charCod ...
- C++ count_if/erase/remove_if 用法详解
每次使用这几个算法时都要去查CPP reference,为了能够加深印象,整理一下基本应用. cout/cout_if: return the number of elements satisfyi ...
- C 语言实现字符串替换
void replaceFirst(char *str1,char *str2,char *str3) { ]; char *p; strcpy(str4,str1); if((p=strstr(st ...
- 如何解决chrome 等浏览器不支持本地ajax请求的问题
XMLHttpRequest cannot load file:///D:/WWW/angularlx/ui-router-test/template/content.html. Cross orig ...
- centos7安装redis3.0和phpredis扩展详细教程(图文)
整理一下centos7安装redis3.0和phpredis扩展的过程,有需要的朋友可以拿去使用. 一.安装redis3.0 1.安装必要的包 yum install gcc 2.centos7安装r ...