标签:arch 程序配置 框架 vs2015 useful sed rename time sig
8.0 版本的 Naked Objects Framework 提供了新的用户界面,不仅外观不一样,还提供了‘Single Page’ 架构(SPA)。 写的客户端编译成 JavaScript,使用 Angular.js 框架 (version 1.5),提供了大量本地执行的功能。APA使用 Restful API通讯,卷宗 Restful Objects 1.1 公共规范 (详见 www.restfulobjects.org )。
8.1 版本引入三个新的强大功能:
修复了一些小 bug 。
重要提示: 8.1版本使用 TypeScript 2。确保安装了 TypeScript 2 , Naked Objects 项目从 8.0升级后,项目会被配置成 TypeScript 2。
接下来 SemVer 约定, 8.1 添加新的不中断现有已发布 API的能力。鉴于这个因素,此手册依然可用于 8.0,不会在使用新功能时候产生异常。
第一次开始 NOF8,或将 NOF8 运行项目添加到现有的 NOF7 应用程序,最好的方式是使用 NakedObjects.Template 项目。你可以从这里下载 .zip文件:
Note: We recommend using the .zipped version of the Template project, rather than taking the source directly from the Master branch of the repository - because the latter is under continusous development and may references versions of packages that have not yet been released publicly on the NuGet gallery.
It should be possible to just run the unzipped project ‘as is’ within Visual Studio 2015 - this starts the server, and the single page application to connect with it.
故障捕获: If, when you start up the application it displays the message ‘Failed to connect to server …’ this usually means that the server has not started up. You can check the log file nakedobjects_log.txt (found in the same directory as the project file) for any errors. The most likely cause is that Entity Framework has been unable to create the database. Check the connection string in Web.config:
<connectionStrings> <add name="NakedObjectsExample" connectionString="Data Source=(LocalDB)\MSSQLLocalDB; Initial Catalog=NakedObjectsExample; Integrated Security=True; MultipleActiveResultSets=True" providerName="System.Data.SqlClient" /> </connectionStrings>
this is set to work with LocalDB, which should be set up by default on VS2015. If you do not have LocalDB set up, try changing the connection string to point to a database that does work for you e.g. SQLEXPRESS.
The Template project contains a minimal 示例模型. Running the project will create the database . You should then be able to create a Customer, and retrieve all saved customers. See also NOF 8 用户界面向导。
Once you have successfully run it. Note the following:
这个示例由两个领域类组成. Customer 是一个 领域对象 (实体) 类:
public class Customer { [NakedObjectsIgnore] public virtual int Id { get; set; } [Title] public virtual string Name { get; set; } }
Note that:
CustomerRepository 是一个领域服务 用于创建和返回这些实体 (严格来讲是结合了 ‘factory’ 和‘repository’ 服务 – 如果你喜欢你可以将这两个角色分到两个服务里):
public class CustomerRepository { public IDomainObjectContainer Container { set; protected get; } public Customer CreateNewCustomer() { return Container.NewTransientInstance<Customer>(); } public IQueryable<Customer> AllCustomers() { return Container.Instances<Customer>(); } public IQueryable<Customer> FindCustomerByName(string name) { return AllCustomers().Where(c => c.Name.ToUpper().Contains(name.ToUpper())); } }
The IDomainObjectContainer is the single point of contact between domain model code and the outside world. Amongst other things, this Container acts as a wrapper for the Entity Framework, so your domain model need not (and should not) have any direct contact with Entity Framework functionality. The container is automatically injected into this repository by the Naked Objects Framework; the container may also be injected into an entity object; and you can use the same pattern to inject an instance of your own services, such as this CustomerRepository, into other services or entities.
领域模型项目包含了使用标准Entity Framework Code First的模式将映射的对象放到数据库里的职责 - 也就是 ExampleDbContext 类的意图:
public class ExampleDbContext : DbContext{ public ExampleDbContext(string dbName) : base(dbName) { Database.SetInitializer<DbContext>(new DropCreateDatabaseIfModelChanges<DbContext>()); } public DbSet<Customer> Customers { get; set; } }
这个示例中领域类型与数据库表是根据默认约定自动映射的; 在真实的项目中,你可能想使用标准Entity Framework模式直接控制映射。 你也可能想提取 DbContext,将领域模型中数据设备类分离到各个项目中。详见 Working with Entity Framework.
Upgrading an existing project from NOF7 to NOF8 is straightforward – at least if you are using the generic Naked Objects user interface. However, any customisations you have made to the generic UI will need to be completely re-written to work in the new Single Page Application client architecture, and you will need to be familiar with TypeScript and Angular to do this. See Adding custom views to the UI.
Note: we do not recommend attempting to upgrade directly to NOF8 from NOF6 or earlier versions of the framework, without having first upgraded to NOF7 and run successfully. (Instructions for upgrading from NOF6 to NOF7 were included in the NOF7 Developer Manual, which may be obtained from the .zip of the NOF7.0 release on GitHub).
If you have an existing application running under NOF 7, then the good news is that no changes are required to your domain model(s). NOF 8.0 has deliberately stayed with the 7.0 Programming Model for this reason. As well as minimising the upgrade effort, the huge advantage of this design decision is that you can run both the NOF 7 client and the NOF 8 client in parallel, against the same domain model(s). Indeed, we recommend running the two in parallel rather than upgrading your existing Run (client) project(s), at least until NOF 8 has gone to full release and you are happy with the new user interface.
We recommend that you create your domain model in separate project(s). A domain model project needs to have the NakedObjects.ProgrammingModel NuGet package installed, but not any other part of the Naked Objects Framework.
Before proceding further we recommend that you install the NakedObjects.Ide NuGet package. This does not contain any run-time code, and is therefore not necessary for writing a Naked Objects application, but it does contain a number of useful file templates and code snippets, that can make writing applications even faster. It is not necessary to have this package installed in each project. Once you’ve installed it into any project, the templates and code snippets will be available on all Visual Studio projects.
Now start to create your domain model, following the patterns and conventions described in Domain model - programming concepts and A how-to guide, and using the short-cuts described in See Using the Naked Objects IDE.
To turn your domain model into an application you will need to add a ‘Run’ project into your solution, and add references to the domain model. By far the best way to so this is to use a copy of Template project, changing the project name and namespaces as desired. Delete the Example Model folder and all references to it in NakedObjectsRunSettings.
Now configure the application, following the guidelines in Application configuration .
标签:arch 程序配置 框架 vs2015 useful sed rename time sig
原文地址:http://www.cnblogs.com/icoolno1/p/6979552.html