Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

合并来自Dev的分支信息。 #5

Merged
merged 5 commits into from
Aug 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ABP框架中文文档/2.4ABP公共结构-日志管理.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.4 ABP公共结构 - 日志管理
# 2.4 ABP公共结构 - 日志管理

### 2.4.1 服务器端

Expand Down
147 changes: 147 additions & 0 deletions ABP框架中文文档/ABP英文文档/About.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
- [Considerations](#considerations)
- [Source codes](#sourcecodes)
- [Contributors](#contributors)
- [Contact](#contact)

ASP.NET Boilerplate was created to help developers build applications using
the best software design practices without repeating themselves. DRY -
**Don't Repeat Yourself!** is the key idea behind ASP.NET Boilerplate.

All applications have some common problems and need some common
structures. ASP.NET Boilerplate works for small projects to large
enterprise web applications, providing a quick start with maintainable
code bases.

### Considerations

Keep these concepts in mind while developing with ASP.NET Boilerplate.

#### Modularity

It should be easy to share [entities](/Pages/Documents/Entities),
[repositories](/Pages/Documents/Repositories),
[services](/Pages/Documents/Application-Services) and views between web
applications. They should be packaged into
[modules](/Pages/Documents/Module-System) and can be easily distributed
(preferred as public/private NuGet packages). Modules may depend on and
use other modules. We should be able to extend models in a module for
our application needs.

Modularity provides us with "code re-usability" (DRY!). For example, we
may develop a module that contains user management, role management,
login and error pages which can be shared by different applications.

#### Best practices

An application should be developed using the best software design
principles. Using [dependency
injection](/Pages/Documents/Dependency-Injection) is one of the most
important subjects in this area. AOP (Aspect Oriented Programming) is
used where it's needed and possible, especially for [cross-cutting
concerns](http://en.wikipedia.org/wiki/Cross-cutting_concern). The
application should also correctly use architectural patterns such as MVC
and MVVM, and it should follow
[SOLID](http://en.wikipedia.org/wiki/SOLID_(object-oriented_design))
principles

Following these best practices makes our code-base more understandable
and extensible. It also prevents us from falling in to common mistakes
that have already been experienced by other developers.

#### Scalable code base

The architecture of an application should provide and enforce a way of
keeping a maintainable code base.
[Layering](/Pages/Documents/NLayer-Architecture) and
[modularity](/Pages/Documents/Module-System) are the main techniques to
accomplish that. Following the best practices is important, otherwise
the application gets complicated when it grows. Many applications have
been rewritten because the code became too unmaintainable.

#### Libraries & Frameworks

An application should use and combine useful libraries & frameworks to
accomplish well-known tasks. It should not try to re-invent the wheel if
an existing tool meets it's requirements, and it should focus on it's
own job (to it's own business logic) as much as possible. The
application may use
[EntityFramework](/Pages/Documents/EntityFramework-Integration) or
[NHibernate](/Pages/Documents/NHibernate-Integration) for
Object-Relational Mapping, and it may also use
[Angular](https://angular.io/) or
[DurandalJs](http://durandaljs.com/) as a Single-Page Application
framework.

Like it or not, we need to learn many different tools to build an
application, even if it's more complicated on the client side. There are
many libraries (thousands of jQuery plug-ins for instance) and
frameworks, so we should carefully choose our libraries and adapt them
for our application.

ASP.NET Boilerplates composes and combines some of the best tools out
there, but it also does not prevent you from using your own favourite
tools.

#### Cross-cutting concerns

Authorization,
[validation](/Pages/Documents/Validating-Data-Transfer-Objects), [error
handling](/Pages/Documents/Handling-Exceptions),
[logging](/Pages/Documents/Logging), caching are common things all
applications implement at some level. The code should be generic and
shared by different applications. It should also be separated from the
business logic code and should be automated as much as possible. This
allows us to focus more on our application specific business logic and
prevents us from re-coding the same stuff over and over again (DRY!).

#### More automation

If it can be automated, it should be automated (at least in most cases).
Database migrations, unit tests, and deployments are some of the tasks
that can be automated. Automation saves us time in a long term and
prevents from making mistakes of manual tasks (DRY!).

#### Convention over configuration

[Convention over
configuration](http://en.wikipedia.org/wiki/Convention_over_configuration)
is a very popular software design principle. An application framework
should implement defaults as much as possible. It should be easy when
following conventions but also configurable when needed.

#### Project startup

It should be easy and fast to start a new application. We should not
repeat some tedious steps to create an empty application (DRY!). A
Project/Solution [templates](/Templates) is a proper way of doing it.

### Source code

ASP.NET Boilerplate is an open source project developed on GitHub.

- Source code:
<https://github.com/aspnetboilerplate/aspnetboilerplate>
- Project templates:
<https://github.com/aspnetboilerplate/aspnetboilerplate-templates>
- Sample projects:
<https://github.com/aspnetboilerplate/aspnetboilerplate-samples>
- Module Zero: <https://github.com/aspnetboilerplate/module-zero>

### Contributors

ASP.NET Boilerplate is designed and developed by [Halil İbrahim
Kalkan](http://www.halilibrahimkalkan.com/). There are also many
[contributors](https://github.com/aspnetboilerplate/aspnetboilerplate/graphs/contributors)
on GitHub. Please feel free to fork our repositories and send pull
requests!

### Contact

For your questions and other discussions, use [official
forum](http://forum.aspnetboilerplate.com/).

For feature requests or bug reports, use [GitHub
issues](https://github.com/aspnetboilerplate/aspnetboilerplate/issues).

For personal contact with me, visit my [web
page](http://halilibrahimkalkan.com/contact/).
113 changes: 113 additions & 0 deletions ABP框架中文文档/ABP英文文档/Abp-Session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
### Introduction

ASP.NET Boilerplate provides an **IAbpSession** interface to obtain the current
user and tenant **without** using ASP.NET's Session. IAbpSession is also
fully integrated and used by other structures in ASP.NET Boilerplate such as the
[setting](Setting-Management.md) and
[authorization](Authorization.md) systems.

### Injecting Session

IAbpSession is generally **[property
injected](/Pages/Documents/Dependency-Injection#property-injection-pattern)**
to needed classes unless it's not possible to work without session
information. If we use property injection, we can use
**NullAbpSession.Instance** as a default value, as shown below:

public class MyClass : ITransientDependency
{
public IAbpSession AbpSession { get; set; }

public MyClass()
{
AbpSession = NullAbpSession.Instance;
}

public void MyMethod()
{
var currentUserId = AbpSession.UserId;
//...
}
}

Since authentication/authorization is an application layer task, it's
advisable to **use the IAbpSession in the application layer and upper layers**.
This is not generally done in the domain layer. **ApplicationService**,
**AbpController,** **AbpApiController** and some other base classes have
**AbpSession** already injected, so you can, for instance, directly use the
AbpSession property in an application service method.

### Session Properties

AbpSession defines a few key properties:

- **UserId**: Id of the current user or null if there is no current
user. It can not be null if the calling code is authorized.
- **TenantId**: Id of the current tenant or null if there is no
current tenant (in case of user has not logged in or he is a host
user).
- **ImpersonatorUserId**: Id of the impersonator user, if the current
session is impersonated by another user. It's null if this is not an
impersonated login.
- **ImpersonatorTenantId**: Id of the impersonator user's tenant, if
the current session is impersonated by another user. It's null if this
is not an impersonated login.
- **MultiTenancySide**: It may be Host or Tenant.

UserId and TenantId is **nullable**. There are also the non-nullable
**GetUserId()** and **GetTenantId()** methods. If you're sure there is a
current user, you can call GetUserId(). If the current user is null, this
method throws an exception. GetTenantId() also works in this way.

Impersonator properties are not as common as other properties and are
generally used for [audit logging](/Pages/Documents/Audit-Logging) purposes.

**ClaimsAbpSession**

ClaimsAbpSession is the **default implementation** of the IAbpSession
interface. It gets session properties (except MultiTenancySide, it's
calculated) from the claims of the current user's principal. For a cookie-based
form authentication, it gets the values from cookies. Thus, it's fully integrated
in to ASP.NET's authentication mechanism.

### Overriding Current Session Values

In some specific cases, you may need to change/override session values
for a limited scope. In such cases, you can use the IAbpSession.Use method
as shown below:

public class MyService
{
private readonly IAbpSession _session;

public MyService(IAbpSession session)
{
_session = session;
}

public void Test()
{
using (_session.Use(42, null))
{
var tenantId = _session.TenantId; //42
var userId = _session.UserId; //null
}
}
}

The Use method returns an IDisposable and it **must be disposed**. Once the
return value is disposed, Session values are **automatically restored**
the to previous values.

#### Warning!

Always use the Use method in a using block as shown above. Otherwise, you may
get unexpected session values. You can have nested Use blocks and they will
work as you expect.

### User Identifier

You can use **.ToUserIdentifier()** extension method to create a
UserIdentifier object from IAbpSession. Since UserIdentifier is used in
a lot of APIs, this will simplify the creation of a UserIdentifier object for the
current user.
Loading