mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Correct package version installed
Dependency injection works Project renaming WIP replacement of services with CQRS
This commit is contained in:
@@ -1,25 +1,27 @@
|
||||
using Autofac;
|
||||
using System.Reflection;
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Infrastructure.KeePass;
|
||||
using ModernKeePass.Infrastructure.UWP;
|
||||
|
||||
namespace ModernKeePass.Infrastructure
|
||||
{
|
||||
public class DependencyInjection: Module
|
||||
public static class DependencyInjection
|
||||
{
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
public static IServiceCollection AddInfrastructure(this IServiceCollection services)
|
||||
{
|
||||
builder.RegisterType<KeePassDatabaseClient>().As<IDatabaseProxy>().SingleInstance();
|
||||
builder.RegisterType<KeePassPasswordClient>().As<IPasswordProxy>().SingleInstance();
|
||||
builder.RegisterType<KeePassCryptographyClient>().As<ICryptographyClient>();
|
||||
builder.RegisterType<UwpSettingsClient>().As<ISettingsProxy>();
|
||||
builder.RegisterType<UwpResourceClient>().As<IResourceProxy>();
|
||||
builder.RegisterType<UwpRecentFilesClient>().As<IRecentProxy>();
|
||||
builder.RegisterType<StorageFileClient>().As<IFileProxy>();
|
||||
var assembly = typeof(DependencyInjection).GetTypeInfo().Assembly;
|
||||
services.AddAutoMapper(assembly);
|
||||
|
||||
// Register Automapper profiles
|
||||
builder.RegisterType<EntryMappingProfile>().As<Profile>();
|
||||
services.AddSingleton(typeof(IDatabaseProxy), typeof(KeePassDatabaseClient));
|
||||
services.AddTransient(typeof(ICryptographyClient), typeof(KeePassCryptographyClient));
|
||||
services.AddTransient(typeof(IPasswordProxy), typeof(KeePassPasswordClient));
|
||||
services.AddTransient(typeof(IResourceProxy), typeof(UwpResourceClient));
|
||||
services.AddTransient(typeof(ISettingsProxy), typeof(UwpSettingsClient));
|
||||
services.AddTransient(typeof(IRecentProxy), typeof(UwpRecentFilesClient));
|
||||
services.AddTransient(typeof(IFileProxy), typeof(StorageFileClient));
|
||||
return services;
|
||||
}
|
||||
}
|
||||
}
|
@@ -41,6 +41,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DependencyInjection.cs" />
|
||||
<Compile Include="InfrastructureModule.cs" />
|
||||
<Compile Include="File\CsvImportFormat.cs" />
|
||||
<Compile Include="KeePass\EntryMappingProfile.cs" />
|
||||
<Compile Include="KeePass\IconMapper.cs" />
|
||||
@@ -54,19 +55,20 @@
|
||||
<Compile Include="UWP\UwpSettingsClient.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ModernKeePass.Application\ModernKeePass.Application.csproj">
|
||||
<ProjectReference Include="..\ModernKeePass.Application\Application.csproj">
|
||||
<Project>{42353562-5e43-459c-8e3e-2f21e575261d}</Project>
|
||||
<Name>ModernKeePass.Application</Name>
|
||||
<Name>Application</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\ModernKeePass.Domain\ModernKeePass.Domain.csproj">
|
||||
<ProjectReference Include="..\ModernKeePass.Domain\Domain.csproj">
|
||||
<Project>{9a0759f1-9069-4841-99e3-3bec44e17356}</Project>
|
||||
<Name>ModernKeePass.Domain</Name>
|
||||
<Name>Domain</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Windows, Version=255.255.255.255, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>Libs\Windows.winmd</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
25
ModernKeePass.Infrastructure/InfrastructureModule.cs
Normal file
25
ModernKeePass.Infrastructure/InfrastructureModule.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Autofac;
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
using ModernKeePass.Infrastructure.KeePass;
|
||||
using ModernKeePass.Infrastructure.UWP;
|
||||
|
||||
namespace ModernKeePass.Infrastructure
|
||||
{
|
||||
public class InfrastructureModule: Module
|
||||
{
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterType<KeePassDatabaseClient>().As<IDatabaseProxy>().SingleInstance();
|
||||
builder.RegisterType<KeePassPasswordClient>().As<IPasswordProxy>().SingleInstance();
|
||||
builder.RegisterType<KeePassCryptographyClient>().As<ICryptographyClient>();
|
||||
builder.RegisterType<UwpSettingsClient>().As<ISettingsProxy>();
|
||||
builder.RegisterType<UwpResourceClient>().As<IResourceProxy>();
|
||||
builder.RegisterType<UwpRecentFilesClient>().As<IRecentProxy>();
|
||||
builder.RegisterType<StorageFileClient>().As<IFileProxy>();
|
||||
|
||||
// Register Automapper profiles
|
||||
builder.RegisterType<EntryMappingProfile>().As<Profile>();
|
||||
}
|
||||
}
|
||||
}
|
@@ -17,6 +17,7 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
|
||||
private void FromDtoToModel()
|
||||
{
|
||||
Uri url;
|
||||
CreateMap<PwEntry, EntryEntity>()
|
||||
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Uuid.ToHexString()))
|
||||
.ForMember(dest => dest.Name, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.TitleField)))
|
||||
@@ -24,7 +25,7 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
.ForMember(dest => dest.Password, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.PasswordField)))
|
||||
.ForMember(dest => dest.Url, opt =>
|
||||
{
|
||||
opt.PreCondition(src => Uri.TryCreate(GetEntryValue(src, PwDefs.UrlField), UriKind.Absolute, out _));
|
||||
opt.PreCondition(src => Uri.TryCreate(GetEntryValue(src, PwDefs.UrlField), UriKind.Absolute, out url));
|
||||
opt.MapFrom(src => new Uri(GetEntryValue(src, PwDefs.UrlField)));
|
||||
})
|
||||
.ForMember(dest => dest.Notes, opt => opt.MapFrom(src => GetEntryValue(src, PwDefs.NotesField)))
|
||||
|
@@ -26,6 +26,7 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
private CompositeKey _compositeKey;
|
||||
|
||||
public bool IsOpen => (_pwDatabase?.IsOpen).GetValueOrDefault();
|
||||
public string Name => _pwDatabase?.Name;
|
||||
|
||||
public GroupEntity RecycleBin { get; set; }
|
||||
|
||||
@@ -40,7 +41,7 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
Name = cipher.DisplayName
|
||||
};
|
||||
}
|
||||
set => _pwDatabase.DataCipherUuid = BuildIdFromString(value.Id);
|
||||
set { _pwDatabase.DataCipherUuid = BuildIdFromString(value.Id); }
|
||||
}
|
||||
|
||||
public BaseEntity KeyDerivation
|
||||
@@ -53,15 +54,18 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
Id = keyDerivation.Uuid.ToHexString(),
|
||||
Name = keyDerivation.Name
|
||||
};
|
||||
}
|
||||
set => _pwDatabase.KdfParameters = KdfPool.Engines
|
||||
.FirstOrDefault(e => e.Uuid.Equals(BuildIdFromString(value.Name)))?.GetDefaultParameters();
|
||||
}
|
||||
set
|
||||
{
|
||||
_pwDatabase.KdfParameters = KdfPool.Engines
|
||||
.FirstOrDefault(e => e.Uuid.Equals(BuildIdFromString(value.Name)))?.GetDefaultParameters();
|
||||
}
|
||||
}
|
||||
|
||||
public string Compression
|
||||
{
|
||||
get => _pwDatabase.Compression.ToString("G");
|
||||
set => _pwDatabase.Compression = (PwCompressionAlgorithm)Enum.Parse(typeof(PwCompressionAlgorithm), value);
|
||||
get { return _pwDatabase.Compression.ToString("G"); }
|
||||
set { _pwDatabase.Compression = (PwCompressionAlgorithm) Enum.Parse(typeof(PwCompressionAlgorithm), value); }
|
||||
}
|
||||
|
||||
public KeePassDatabaseClient(ISettingsProxy settings, IFileProxy fileService, IMapper mapper)
|
||||
|
@@ -3,6 +3,7 @@ using ModernKeePass.Domain.Dtos;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Cryptography.PasswordGenerator;
|
||||
using ModernKeePassLib.Keys;
|
||||
using ModernKeePassLib.Security;
|
||||
|
||||
namespace ModernKeePass.Infrastructure.KeePass
|
||||
{
|
||||
@@ -28,7 +29,8 @@ namespace ModernKeePass.Infrastructure.KeePass
|
||||
|
||||
pwProfile.CharSet.Add(options.CustomChars);
|
||||
|
||||
PwGenerator.Generate(out var password, pwProfile, null, new CustomPwGeneratorPool());
|
||||
ProtectedString password;
|
||||
PwGenerator.Generate(out password, pwProfile, null, new CustomPwGeneratorPool());
|
||||
|
||||
return password.ReadString();
|
||||
}
|
||||
|
@@ -9,7 +9,7 @@ namespace ModernKeePass.Infrastructure.UWP
|
||||
{
|
||||
private readonly IPropertySet _values = ApplicationData.Current.LocalSettings.Values;
|
||||
|
||||
public T GetSetting<T>(string property, T defaultValue = default)
|
||||
public T GetSetting<T>(string property, T defaultValue = default(T))
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@@ -1,9 +1,11 @@
|
||||
{
|
||||
"supports": {},
|
||||
"dependencies": {
|
||||
"AutoMapper": "6.1.1",
|
||||
"AutoMapper.Extensions.Microsoft.DependencyInjection": "2.0.1",
|
||||
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
|
||||
"ModernKeePassLib": "2.44.1",
|
||||
"NETStandard.Library": "1.6.1"
|
||||
"NETStandard.Library": "2.0.3"
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.2": {}
|
||||
|
Reference in New Issue
Block a user