Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
netcoreplus
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
netcoreplus
Commits
2aa84847
Commit
2aa84847
authored
May 28, 2019
by
阿星Plus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dependency
parent
abb12214
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
342 additions
and
108 deletions
+342
-108
DefaultDbContextResolver.cs
src/Plus.EntityFramework/DefaultDbContextResolver.cs
+4
-1
BasicConventionalRegistrar.cs
src/Plus/Dependency/BasicConventionalRegistrar.cs
+2
-13
ConventionalRegistrationConfig.cs
src/Plus/Dependency/ConventionalRegistrationConfig.cs
+25
-0
ConventionalRegistrationContext.cs
src/Plus/Dependency/ConventionalRegistrationContext.cs
+19
-12
IConventionalDependencyRegistrar.cs
src/Plus/Dependency/IConventionalDependencyRegistrar.cs
+10
-0
IConventionalRegistrationContext.cs
src/Plus/Dependency/IConventionalRegistrationContext.cs
+25
-0
IIocRegistrar.cs
src/Plus/Dependency/IIocRegistrar.cs
+34
-26
IIocResolver.cs
src/Plus/Dependency/IIocResolver.cs
+72
-34
IocManager.cs
src/Plus/Dependency/IocManager.cs
+149
-20
Plus.csproj
src/Plus/Plus.csproj
+1
-1
PlusLeadershipModule.cs
src/Plus/PlusLeadershipModule.cs
+1
-1
No files found.
src/Plus.EntityFramework/DefaultDbContextResolver.cs
View file @
2aa84847
...
...
@@ -48,7 +48,10 @@ namespace Plus.EntityFramework
});
}
return
_iocResolver
.
Resolve
<
TDbContext
>(
concreteType
);
return
_iocResolver
.
Resolve
<
TDbContext
>(
new
{
options
=
CreateOptions
<
TDbContext
>(
connectionString
,
existingConnection
)
});
}
catch
(
DependencyResolverException
ex
)
{
...
...
src/Plus/Dependency/BasicConventionalRegistrar.cs
View file @
2aa84847
using
Castle.DynamicProxy
;
using
Castle.MicroKernel.Registration
;
using
Plus.Event
;
using
System.Reflection
;
namespace
Plus.Dependency
...
...
@@ -8,9 +7,9 @@ namespace Plus.Dependency
/// <summary>
/// 用于注册基本依赖项实现
/// </summary>
public
class
BasicConventionalRegistrar
:
IDependencyRegistrar
public
class
BasicConventionalRegistrar
:
I
Conventional
DependencyRegistrar
{
public
void
RegisterAssembly
(
IRegistrationContext
context
)
public
void
RegisterAssembly
(
I
Conventional
RegistrationContext
context
)
{
//Transient
context
.
IocManager
.
IocContainer
.
Register
(
...
...
@@ -43,16 +42,6 @@ namespace Plus.Dependency
.
WithService
.
Self
()
.
LifestyleTransient
()
);
//IConsumer
context
.
IocManager
.
IocContainer
.
Register
(
Classes
.
FromAssembly
(
context
.
Assembly
)
.
IncludeNonPublicTypes
()
.
BasedOn
(
typeof
(
IConsumer
<>))
.
If
(
type
=>
!
type
.
GetTypeInfo
().
IsGenericTypeDefinition
)
.
WithService
.
Self
()
.
LifestyleTransient
()
);
}
}
}
\ No newline at end of file
src/Plus/Dependency/ConventionalRegistrationConfig.cs
0 → 100644
View file @
2aa84847
using
Castle.DynamicProxy
;
using
Plus.Configuration
;
namespace
Plus.Dependency
{
/// <summary>
/// ConventionalRegistrationConfig
/// </summary>
public
class
ConventionalRegistrationConfig
:
DictionaryBasedConfig
{
/// <summary>
/// Install all <see cref="IInterceptor"/> implementations automatically or not.
/// Default: true.
/// </summary>
public
bool
InstallInstallers
{
get
;
set
;
}
/// <summary>
/// Creates a new <see cref="ConventionalRegistrationConfig"/> object.
/// </summary>
public
ConventionalRegistrationConfig
()
{
InstallInstallers
=
true
;
}
}
}
\ No newline at end of file
src/Plus/Dependency/ConventionalRegistrationContext.cs
View file @
2aa84847
...
...
@@ -2,24 +2,31 @@
namespace
Plus.Dependency
{
public
class
ConventionalRegistrationContext
:
IRegistrationContext
/// <summary>
/// ConventionalRegistrationContext
/// </summary>
internal
class
ConventionalRegistrationContext
:
IConventionalRegistrationContext
{
public
Assembly
Assembly
{
get
;
private
set
;
}
/// <summary>
/// Gets the registering Assembly.
/// </summary>
public
Assembly
Assembly
{
get
;
private
set
;
}
public
IIocManager
IocManager
{
get
;
private
set
;
}
/// <summary>
/// Reference to the IOC Container to register types.
/// </summary>
public
IIocManager
IocManager
{
get
;
private
set
;
}
/// <summary>
/// Registration configuration.
/// </summary>
public
ConventionalRegistrationConfig
Config
{
get
;
private
set
;
}
internal
ConventionalRegistrationContext
(
Assembly
assembly
,
IIocManager
iocManager
)
internal
ConventionalRegistrationContext
(
Assembly
assembly
,
IIocManager
iocManager
,
ConventionalRegistrationConfig
config
)
{
Assembly
=
assembly
;
IocManager
=
iocManager
;
Config
=
config
;
}
}
}
\ No newline at end of file
src/Plus/Dependency/IConventionalDependencyRegistrar.cs
0 → 100644
View file @
2aa84847
namespace
Plus.Dependency
{
/// <summary>
/// IConventionalDependencyRegistrar
/// </summary>
public
interface
IConventionalDependencyRegistrar
{
void
RegisterAssembly
(
IConventionalRegistrationContext
context
);
}
}
\ No newline at end of file
src/Plus/Dependency/IConventionalRegistrationContext.cs
0 → 100644
View file @
2aa84847
using
System.Reflection
;
namespace
Plus.Dependency
{
/// <summary>
/// IConventionalRegistrationContext
/// </summary>
public
interface
IConventionalRegistrationContext
{
/// <summary>
/// Gets the registering Assembly.
/// </summary>
Assembly
Assembly
{
get
;
}
/// <summary>
/// Reference to the IOC Container to register types.
/// </summary>
IIocManager
IocManager
{
get
;
}
/// <summary>
/// Registration configuration.
/// </summary>
ConventionalRegistrationConfig
Config
{
get
;
}
}
}
\ No newline at end of file
src/Plus/Dependency/IIocRegistrar.cs
View file @
2aa84847
...
...
@@ -9,59 +9,67 @@ namespace Plus.Dependency
public
interface
IIocRegistrar
{
/// <summary>
/// Add
Registrar
/// Add
s a dependency registrar for conventional registration.
/// </summary>
/// <param name="registrar"></param>
void
Add
Registrar
(
I
DependencyRegistrar
registrar
);
/// <param name="registrar">
dependency registrar
</param>
void
Add
ConventionalRegistrar
(
IConventional
DependencyRegistrar
registrar
);
/// <summary>
/// Register
Assembly
/// Register
s types of given assembly by all conventional registrars. See <see cref="IocManager.AddConventionalRegistrar"/> method.
/// </summary>
/// <param name="assembly"></param>
/// <param name="assembly">
Assembly to register
</param>
void
RegisterAssembly
(
Assembly
assembly
);
/// <summary>
/// Register
/// Register
s types of given assembly by all conventional registrars. See <see cref="IocManager.AddConventionalRegistrar"/> method.
/// </summary>
/// <
typeparam name="T"></type
param>
/// <param name="
lifeStyle">
</param>
void
Register
<
T
>(
DependencyLifeStyle
lifeStyle
=
DependencyLifeStyle
.
Singleton
)
where
T
:
class
;
/// <
param name="assembly">Assembly to register</
param>
/// <param name="
config">Additional configuration
</param>
void
Register
Assembly
(
Assembly
assembly
,
ConventionalRegistrationConfig
config
)
;
/// <summary>
/// Register
/// Register
s a type as self registration.
/// </summary>
/// <param name="type"></param>
/// <param name="lifeStyle"></param>
/// <typeparam name="T">Type of the class</typeparam>
/// <param name="lifeStyle">Lifestyle of the objects of this type</param>
void
Register
<
T
>(
DependencyLifeStyle
lifeStyle
=
DependencyLifeStyle
.
Singleton
)
where
T
:
class
;
/// <summary>
/// Registers a type as self registration.
/// </summary>
/// <param name="type">Type of the class</param>
/// <param name="lifeStyle">Lifestyle of the objects of this type</param>
void
Register
(
Type
type
,
DependencyLifeStyle
lifeStyle
=
DependencyLifeStyle
.
Singleton
);
/// <summary>
/// Register
/// Register
s a type with it's implementation.
/// </summary>
/// <typeparam name="TType"></typeparam>
/// <typeparam name="TImpl"></typeparam>
/// <param name="lifeStyle"></param>
void
Register
<
TType
,
TImpl
>(
DependencyLifeStyle
lifeStyle
=
DependencyLifeStyle
.
Singleton
)
where
TType
:
class
where
TImpl
:
class
,
TType
;
void
Register
<
TType
,
TImpl
>(
DependencyLifeStyle
lifeStyle
=
DependencyLifeStyle
.
Singleton
)
where
TType
:
class
where
TImpl
:
class
,
TType
;
/// <summary>
/// Register
/// Register
s a type with it's implementation.
/// </summary>
/// <param name="type"></param>
/// <param name="impl"></param>
/// <param name="lifeStyle"></param>
/// <param name="type">
Type of the class
</param>
/// <param name="impl">
The type that implements <paramref name="type"/>
</param>
/// <param name="lifeStyle">
Lifestyle of the objects of this type
</param>
void
Register
(
Type
type
,
Type
impl
,
DependencyLifeStyle
lifeStyle
=
DependencyLifeStyle
.
Singleton
);
/// <summary>
///
是否注册了给定的类型
///
Checks whether given type is registered before.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
bool
IsRegistered
<
T
>();
/// <param name="type">Type to check</param>
bool
IsRegistered
(
Type
type
);
/// <summary>
///
是否注册了给定的类型
///
Checks whether given type is registered before.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
bool
IsRegistered
(
Type
type
);
/// <typeparam name="TType">Type to check</typeparam>
bool
IsRegistered
<
TType
>();
}
}
\ No newline at end of file
src/Plus/Dependency/IIocResolver.cs
View file @
2aa84847
...
...
@@ -8,60 +8,98 @@ namespace Plus.Dependency
public
interface
IIocResolver
{
/// <summary>
/// 从IOC容器中获取对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
/// Gets an object from IOC container.
/// Returning object must be Released (see <see cref="Release"/>) after usage.
/// </summary>
/// <typeparam name="T">Type of the object to get</typeparam>
/// <returns>The object instance</returns>
T
Resolve
<
T
>();
/// <summary>
/// 从IOC容器中获取对象
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
/// Gets an object from IOC container.
/// Returning object must be Released (see <see cref="Release"/>) after usage.
/// </summary>
/// <typeparam name="T">Type of the object to cast</typeparam>
/// <param name="type">Type of the object to resolve</param>
/// <returns>The object instance</returns>
T
Resolve
<
T
>(
Type
type
);
/// <summary>
/// Gets an object from IOC container.
/// Returning object must be Released (see <see cref="Release"/>) after usage.
/// </summary>
/// <typeparam name="T">Type of the object to get</typeparam>
/// <param name="argumentsAsAnonymousType">Constructor arguments</param>
/// <returns>The object instance</returns>
T
Resolve
<
T
>(
object
argumentsAsAnonymousType
);
/// <summary>
/// Gets an object from IOC container.
/// Returning object must be Released (see <see cref="Release"/>) after usage.
/// </summary>
/// <param name="type">Type of the object to get</param>
/// <returns>The object instance</returns>
object
Resolve
(
Type
type
);
/// <summary>
/// 从IOC容器中获取对象
/// </summary>
/// <param name="type"></param>
/// <param name="argumentsAsAnonymousType"></param>
/// <returns></returns>
/// Gets an object from IOC container.
/// Returning object must be Released (see <see cref="Release"/>) after usage.
/// </summary>
/// <param name="type">Type of the object to get</param>
/// <param name="argumentsAsAnonymousType">Constructor arguments</param>
/// <returns>The object instance</returns>
object
Resolve
(
Type
type
,
object
argumentsAsAnonymousType
);
/// <summary>
///
从IOC容器中获取对象
///
</summary>
/// <
typeparam name="T"></typeparam>
/// <
param name="argumentsAsAnonymousType"></
param>
/// <returns></returns>
T
Resolve
<
T
>(
object
argumentsAsAnonymousType
);
///
Gets all implementations for given type.
///
Returning objects must be Released (see <see cref="Release"/>) after usage.
/// <
/summary>
/// <
typeparam name="T">Type of the objects to resolve</type
param>
/// <returns>
Object instances
</returns>
T
[]
ResolveAll
<
T
>(
);
/// <summary>
/// 从IOC容器中获取对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
T
[]
ResolveAll
<
T
>();
/// Gets all implementations for given type.
/// Returning objects must be Released (see <see cref="Release"/>) after usage.
/// </summary>
/// <typeparam name="T">Type of the objects to resolve</typeparam>
/// <param name="argumentsAsAnonymousType">Constructor arguments</param>
/// <returns>Object instances</returns>
T
[]
ResolveAll
<
T
>(
object
argumentsAsAnonymousType
);
/// <summary>
/// Gets all implementations for given type.
/// Returning objects must be Released (see <see cref="Release"/>) after usage.
/// </summary>
/// <param name="type">Type of the objects to resolve</param>
/// <returns>Object instances</returns>
object
[]
ResolveAll
(
Type
type
);
/// <summary>
/// Gets all implementations for given type.
/// Returning objects must be Released (see <see cref="Release"/>) after usage.
/// </summary>
/// <param name="type">Type of the objects to resolve</param>
/// <param name="argumentsAsAnonymousType">Constructor arguments</param>
/// <returns>Object instances</returns>
object
[]
ResolveAll
(
Type
type
,
object
argumentsAsAnonymousType
);
/// <summary>
///
是否注册了给定的类型
///
Releases a pre-resolved object. See Resolve methods.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <returns></returns>
bool
IsRegistered
<
T
>();
/// <param name="obj">Object to be released</param>
void
Release
(
object
obj
);
/// <summary>
///
是否注册了给定的类型
///
Checks whether given type is registered before.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
/// <param name="type">Type to check</param>
bool
IsRegistered
(
Type
type
);
/// <summary>
///
释放预解析对象
///
Checks whether given type is registered before.
/// </summary>
/// <
param name="obj"></
param>
void
Release
(
object
obj
);
/// <
typeparam name="T">Type to check</type
param>
bool
IsRegistered
<
T
>(
);
}
}
\ No newline at end of file
src/Plus/Dependency/IocManager.cs
View file @
2aa84847
This diff is collapsed.
Click to expand it.
src/Plus/Plus.csproj
View file @
2aa84847
...
...
@@ -32,7 +32,7 @@
<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.4.0" />
<PackageReference Include="Castle.LoggingFacility" Version="
4.1.1
" />
<PackageReference Include="Castle.LoggingFacility" Version="
5.0.0
" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="2.2.0" />
...
...
src/Plus/PlusLeadershipModule.cs
View file @
2aa84847
...
...
@@ -18,7 +18,7 @@ namespace Plus
{
public
override
void
PreInitialize
()
{
IocManager
.
AddRegistrar
(
new
BasicConventionalRegistrar
());
IocManager
.
Add
Conventional
Registrar
(
new
BasicConventionalRegistrar
());
ConfigureCaches
();
AddIgnoredTypes
();
AddMethodParameterValidators
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment