Nop-Fluent+AutoFAC模式在ASP.NET MVC中的应用场景<四>
来源:互联网 发布:平价洗面奶 知乎 编辑:程序博客网 时间:2024/06/06 05:30
Nop-Fluent+AutoFAC模式在ASP.NET MVC中的应用场景<四>
分类: Nop Commerce2012-02-23 15:14 23人阅读 评论(0) 收藏 举报
Fluent+AutoFAC模式在ASP.NET MVC中的应用场景:
话说应该先介绍一些IoC或者Dependency Injection之类的东西,但我确实是才学这些不多久,虽然接触ASP.NET许久。
通过添加引用autofac,完成autofac的基本注册,等于完成autofac的asp.net MVC集成。Web.config中添加:
<httpModules> <add name="ContainerDisposal" type="Autofac.Integration.Web.ContainerDisposalModule,Autofac.Integration.Web"/> <add name="PropertyInjection" type ="Autofac.Integration.Web.Forms.PropertyInjectionModule,Autofac.Integration.Web"/> </httpModules>
例如在DependencyRegistrar.cs中
builder.RegisterType<GeoCountryLookup>().As<IGeoCountryLookup>().InstancePerHttpRequest(); builder.RegisterType<CountryService>().As<ICountryService>().InstancePerHttpRequest();
在Global.asax中register Person。
Validation部分:
先添加引用:
由于使用了Ioc,我们看到在Controller中也可以使用带有参数的方式了:
ModelValidatorProviders.Providers.Add( new FluentValidationModelValidatorProvider(new NopValidatorFactory()));
通过在Model类对象上使用Validator Attribute实现自动的验证
using FluentValidation.Attributes;
[Validator(typeof(NewsItemValidator))] public class NewsItemModel : BaseNopEntityModel { [NopResourceDisplayName("Admin.ContentManagement.News.NewsItems.Fields.Language")] public int LanguageId { get; set; }
在Admin的Model中以及front Web的Model中
[Validator(typeof(NewsItemValidator))] public class NewsItemModel : BaseNopEntityModel { public NewsItemModel() { Tags = new List<string>(); Comments = new List<NewsCommentModel>(); AddNewComment = new AddNewsCommentModel(); }
。。 。。。 。。。
更多详细资料,请参考http://code.google.com/p/autofac/
http://code.google.com/p/autofac/wiki/AspNetIntegration
- Nop-Fluent+AutoFAC模式在ASP.NET MVC中的应用场景<四>
- Nop-Fluent+AutoFAC模式在ASP.NET MVC中的应用场景<四>
- Autofac在ASP.NET MVC中的使用
- MVC模式在ASP.NET中的应用
- MVC模式在ASP.NET中的应用
- MVC模式在ASP.NET中的应用
- MVC模式在ASP.NET Web页面中的应用
- MVC模式在ASP.NET中的应用(示例)
- Fluent NHibernate & ASP.NET MVC
- ASP.NET中的MVC模式应用
- ASP.NET中的MVC模式应用
- SignalR在ASP.NET MVC中的应用
- System.Web.Abstractions中的装饰者模式,及其在Asp.net Mvc中的应用
- Ioc容器Autofac asp.net mvc中整合autofac
- Nop-ASP.NET MVC Area概念的应用Admin后台项目<三>
- Nop-ASP.NET MVC Area概念的应用Admin后台项目<三>
- ASP.NET MVC IOC 之AutoFac攻略
- ASP.NET MVC IOC 之AutoFac攻略
- 关于JavaScript的闭包
- Nop-ASP.NET MVC Area概念的应用Admin后台项目<三>
- Oracle 行列转换问题总结
- 关于S5PV210的启动问题和u-boot分析并自己实现一个简单的boot(一)
- Struts详解(二)常用变量
- Nop-Fluent+AutoFAC模式在ASP.NET MVC中的应用场景<四>
- 虚拟机VMware7.0.0安装CentOS-6.2出现fatal IO error 104 connection reset by peer on xserver:1.0解决
- 新站排名为何会如此跌宕起伏
- fopen返回值问题
- CreateThread, AfxBeginThread,_beginthread, _beginthreadex的区别
- Nop- Automapper在Nopcommerce中的使用<五>
- 运行java和classpath
- PHP-UBB&hightlight 函数
- 如何应用Entity Framework进行数据访问