Comments (3)
Looking at this... I'm not sure this would fit in your "MicroBus" idea. Seems like it would quickly get out of scope:
public static class BusBuilderExtensions
{
internal class DependencyScope : IDependencyScope
{
readonly List<object> objects = new List<object>();
public void AddObject(object obj)
{
objects.Add(obj);
}
public void AddObjects(object obj, params object[] objs)
{
objects.Add(obj);
foreach (var o in objs)
{
this.objects.Add(o);
}
}
public IDependencyScope BeginScope()
{
return this;
}
public void Dispose()
{
}
public object GetService(Type serviceType)
{
return GetServices(serviceType).Single();
}
public T GetService<T>()
{
return (T)GetService(typeof(T));
}
public IEnumerable<object> GetServices(Type serviceType)
{
return objects.Where(o => ReflectionExtensions.ExpandType(o.GetType()).Contains(serviceType)).ToArray();
}
public IEnumerable<T> GetServices<T>()
{
return GetServices(typeof(T)).Cast<T>();
}
}
public static IDependencyScope GetDependencyScope(this BusBuilder busBuilder, BusSettings busSettings = null)
{
if (busBuilder == null) throw new ArgumentNullException(nameof(busBuilder));
var piplineBuilder = new PipelineBuilder(busBuilder);
piplineBuilder.Validate();
var dependencyScope = new DependencyScope();
dependencyScope.AddObject(busBuilder);
foreach (var reg in busBuilder.GlobalHandlerRegistrations)
{
dependencyScope.AddObject(Activator.CreateInstance(reg.HandlerType, false));
}
foreach (var reg in busBuilder.MessageHandlerRegistrations)
{
dependencyScope.AddObject(Activator.CreateInstance(reg.HandlerType, false));
}
var updater = new OuterPipelineDetector();
var pipelineBuilder = new PipelineBuilder(busBuilder);
var pipelineRunBuilder = new PipelineRunBuilder(busSettings ?? new BusSettings(), pipelineBuilder, updater, dependencyScope);
dependencyScope.AddObjects(updater, pipelineBuilder, pipelineRunBuilder);
return dependencyScope;
}
public static MicroBus BuildBus(this BusBuilder busBuilder, BusSettings busSettings = null)
{
if (busBuilder == null) throw new ArgumentNullException(nameof(busBuilder));
return new MicroBus(busBuilder.GetDependencyScope(busSettings));
}
public static MicroBus BuildBus(this IDependencyScope dependencyScope)
{
if (dependencyScope == null) throw new ArgumentNullException(nameof(dependencyScope));
return new MicroBus(dependencyScope);
}
}
from enexure.microbus.
That looks like a nice concept would you think this is useful enough to include in a separate package? Something like Enexure.MicroBus.NoIOC
?
Earlier versions of MicroBus included something like this. However, as you've discovered this quickly leads to just implementing another (much more basic) dependency injection container. So, in the end, I removed it and decided to just use a full container.
Were you hoping to avoid the extra dependency?
from enexure.microbus.
Yeah, but this is a waste of time.
from enexure.microbus.
Related Issues (20)
- More Examples HOT 4
- ObjectDisposedException when there are two event handlers for the same event and one of them does a send HOT 1
- How to register a MicroBus pre-instantiated Handler HOT 2
- Global Handler - with restrictions HOT 2
- New IoC container - IServiceProvider in AspNetCore HOT 8
- Add support for LightInject HOT 2
- How to use with StructureMap HOT 3
- InvalidDuplicateRegistrationsException on Handler interface HOT 2
- SomehowRecievedTaskWithoutResultException thrown when returning Task.CompletedTask HOT 2
- Add support for function based handlers
- dll unsigned HOT 3
- .NET Core 2.1 Exception
- Enexure.MicroBus.Autofac version 3.6.2 HOT 3
- Saga duplicates task HOT 2
- ObjectDisposedException with Carter + MicroBus HOT 3
- Retry Logic Documentation HOT 3
- Enable Nullable compiler option for safe null checks
- Add interface for a command with result (ICommand<TResult>) HOT 3
- Vulnerability in [email protected] dependency
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from enexure.microbus.