Comments (7)
I'm using 2.1.1 and it does work properly.
What's your setup like?
from opencqrs.
:) I got this issue during xUnit integration tests creation first. To get integration things work right I have injected all in test constructor:
public SomeTestConstructor()
{
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", false, true)
.Build();
var service = new ServiceCollection();
service
.AddOpenCqrs(typeof(TestCommand))
.AddSqlServerProvider(configuration)
.AddServiceBusProvider(configuration);
_serviceProvider = service.BuildServiceProvider();
var builder = new AppStub(_serviceProvider);
builder
.UseOpenCqrs()
.EnsureDomainDbCreated();
_testItemId = Guid.NewGuid();
}
When I got the error i have tried to inject the IHttpContextAccessor by injecting it to service:
services.AddHttpContextAccessor();
The issue was not resolved. So I have cloned the repository, and used service locator for resolver:
public class HandlerResolver : IHandlerResolver
{
private readonly IServiceProvider _serviceProvider;
public HandlerResolver(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public THandler ResolveHandler<THandler>()
{
var handler = _serviceProvider.GetService<THandler>();
if (handler == null)
throw new HandlerNotFoundException(typeof(THandler));
return handler;
}
}
Also I have removed Resolver class and interface, changing references to IServiceProvider directly.
Maybe this was not the best solution, but this was the hot fix to make things work. Hopefully MS will do solve lazy object resolving issue sometimes. :)
from opencqrs.
Emm... I just forgot to clarify, that was really surprised, when found the error in Web API response. This was the main reason WHY I used service locator pattern for IoC container.
Startup file of API:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddAutoMapper();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
// In production, the Angular files will be served from this directory
services.AddSpaStaticFiles(configuration =>
{
configuration.RootPath = "ClientApp/dist";
});
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(o =>
{
o.Authority = Configuration["Authentication:AADInstance"]
+ Configuration["Authentication:TenantId"];
o.Audience = Configuration["Authentication:ClientId"];
o.TokenValidationParameters = new TokenValidationParameters
{
RoleClaimType = ClaimTypes.Role,
ValidateIssuer = true
};
});
services.AddDbContext<EfCoreContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("SqlConnection"),
db => db.MigrationsAssembly("SomeProject.Web")
)
);
services.Configure<AADOptions>(Configuration.GetSection("Authentication"));
services.AddTransient<AADUserSyncService>();
services.AddTransient<GraphApiUserService>();
services.AddOpenCqrs(typeof(CreateFeedbackCommand))
.AddSqlServerProvider(Configuration)
.AddServiceBusProvider(Configuration);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseAuthentication();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action=Index}/{id?}");
});
app.UseSpa(spa =>
{
// To learn more about options for serving an Angular SPA from ASP.NET Core,
// see https://go.microsoft.com/fwlink/?linkid=864501
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseAngularCliServer(npmScript: "start");
}
});
app.UseOpenCqrs().EnsureDomainDbCreated();
}
}
from opencqrs.
I'll have a look as soon as I can, thanks.
from opencqrs.
This is a know bug (#27) but it should happen only on console apps.
from opencqrs.
Thanks @asokalskyy I'll fix this issue in the next release.
from opencqrs.
Fixed in Version 5.3
from opencqrs.
Related Issues (20)
- [Question] About CommandSequence exception handling HOT 3
- Saga Pattern HOT 8
- InvalidOperationException: Unable to resolve service for type HOT 13
- Approximate Date for Snapshot support? HOT 1
- Support for tenant store HOT 1
- Support for custom discriminator in EF Stores HOT 1
- [Question] How can I setup the cosmos db context to use containers with shared throughtput option HOT 2
- How can I setup an ExecutionStrategy with Cosmos EF
- [Question] Is it possible to customize partition key on cosmos store? HOT 1
- Microservices example HOT 1
- Kledex 2.5.1 - Event handlers get called twice HOT 2
- About load Events HOT 5
- Decorate an event handler HOT 3
- Bulk capabilities HOT 3
- [Question] What is the process to contribute? HOT 3
- Following wiki, always getting 'Some services are not able to be constructed HOT 4
- Application templates HOT 8
- [Question] Is there any plan to use Microsoft.Azure.Cosmos ? HOT 2
- Custom handler or service HOT 1
- Kledex adds "everything" to the ServiceCollection twice, or more. HOT 2
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 opencqrs.