devmentors / dnc-dshop.common Goto Github PK
View Code? Open in Web Editor NEW[Distributed .NET Core] Common library for DShop project.
License: MIT License
[Distributed .NET Core] Common library for DShop project.
License: MIT License
There are several places where Task.Result is used. But my suggestion is to use Task.GetAwaiter().GetResult() instead of Task.Result, Please refer quotes from one of the Microsoft's repo
you should avoid using Task.Result and Task.Wait as much as possible as they always encapsulate the inner exception in an AggregateException and replace the message by a generic one (One or more errors occurred), which makes debugging harder. Even if the synchronous version shouldn't be used that often, you should strongly consider using Task.GetAwaiter().GetResult() instead
I want to migrate my registration to native DI of .NET Core.
There a some variation (delegate).
Is this correctl?
public static void AddRabbitMq(this ContainerBuilder builder)
{
builder.Register(context =>
{
var configuration = context.Resolve<IConfiguration>();
var options = configuration.GetOptions<RabbitMqOptions>("rabbitMq");
return options;
}).SingleInstance();
builder.Register(context =>
{
var configuration = context.Resolve<IConfiguration>();
var options = configuration.GetOptions<RawRabbitConfiguration>("rabbitMq");
return options;
}).SingleInstance();
var assembly = Assembly.GetCallingAssembly();
builder.RegisterAssemblyTypes(assembly)
.AsClosedTypesOf(typeof(IEventHandlerRabbitMq<>))
.InstancePerDependency();
builder.RegisterType<BusPublisher>().As<IBusPublisher>()
.InstancePerDependency();
builder.RegisterInstance(DefaultJaeger.Create())
.As<ITracer>()
.SingleInstance()
.PreserveExistingDefaults();
ConfigureBus(builder);
}
private static void ConfigureBus(ContainerBuilder builder)
{
builder.Register<IInstanceFactory>(context =>
{
var options = context.Resolve<RabbitMqOptions>();
var configuration = context.Resolve<RawRabbitConfiguration>();
var namingConventions = new CustomNamingConventions(options.Namespace);
var tracer = context.Resolve<ITracer>();
return RawRabbitFactory.CreateInstanceFactory(new RawRabbitOptions
{
DependencyInjection = ioc =>
{
ioc.AddSingleton(options);
ioc.AddSingleton(configuration);
ioc.AddSingleton<INamingConventions>(namingConventions);
ioc.AddSingleton(tracer);
},
Plugins = p => p
.UseAttributeRouting()
.UseRetryLater()
.UpdateRetryInfo()
.UseMessageContext<CorrelationContext>()
.UseContextForwarding()
});
}).SingleInstance();
builder.Register(context => context.Resolve<IInstanceFactory>().Create());
}
The new version:
public static void AddRabbitMq(this IServiceCollection services, IConfiguration configuration)
{
var optionsMq = configuration.GetOptions<RabbitMqOptions>("rabbitMq");
var optionsRawRabbit = configuration.GetOptions<RawRabbitConfiguration>("rabbitMq");
services.AddSingleton(optionsMq);
services.AddSingleton(optionsRawRabbit);
services.AddScoped(typeof(IBusPublisher), typeof(BusPublisher));
services.RegisterAllImplementedInterface(Assembly.GetEntryAssembly(), typeof(IEventHandlerRabbitMq<>));
var namingConventions = new CustomNamingConventions(optionsMq.Namespace);
var tracer = DefaultJaeger.Create();
services.AddSingleton(tracer);
var rawFactory = RawRabbitFactory.CreateInstanceFactory(new RawRabbitOptions
{
DependencyInjection = ioc =>
{
ioc.AddSingleton(optionsMq);
ioc.AddSingleton(optionsRawRabbit);
ioc.AddSingleton<INamingConventions>(namingConventions);
ioc.AddSingleton(tracer);
},
Plugins = p => p
.UseAttributeRouting()
.UseRetryLater()
.UpdateRetryInfo()
.UseMessageContext<CorrelationContext>()
.UseContextForwarding()
});
services.AddSingleton<IInstanceFactory>(rawFactory);
services.AddSingleton<IBusClient>(rawFactory.Create());
}
The publish message work very well but I have an error when SubscribeEvent, It doesn;t work in Local:
docker run --name rabbitmq -d -p 5672:5672 -p 15672:15672 --hostname rabbitmq rabbitmq:3-management
This is my setting:
"rabbitMq": {
"namespace": "common",
"retries": 3,
"retryInterval": 2,
"username": "guest",
"password": "guest",
"virtualHost": "/",
"port": 5672,
"hostnames": [
"localhost"
],
"requestTimeout": "00:00:30",
"publishConfirmTimeout": "00:00:30",
"recoveryInterval": "00:00:05",
"persistentDeliveryMode": true,
"autoCloseConnection": false,
"automaticRecovery": true,
"topologyRecovery": true,
"exchange": {
"durable": true,
"autoDelete": false,
"type": "Topic"
},
"queue": {
"autoDelete": false,
"durable": true,
"exclusive": false
}
},
Hi @GooRiOn you mentioned that to reload vault version update without restarting the application is pretty simple. Since it uses MemoryConfigurationSource to replace appsettings.json values , it does not support reloadOnChanges. In that case what should be the approach? should we implement IHostedService with Timer?
New pull request for DShop.Common has been created.
You can see it here.
How to connect SQL Server instead of MongoDB in Common?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.