jbogard / contosouniversity Goto Github PK
View Code? Open in Web Editor NEWContoso University sample re-done the way I would build it
License: Apache License 2.0
Contoso University sample re-done the way I would build it
License: Apache License 2.0
Sticking with the idea of eliminating layers and creating slices:
The following two files are never used and can be deleted.
AssignedCourseData.cs
InstructorIndexData.cs
The EnrollmentDateGroup class defined in EnrollmentDateGroup.cs
could be moved into the Home/UiController
class given that is the only scope in which it is being used other than the About.cshtml file, which should be updated to
@model IEnumerable<ContosoUniversity.Features.Home.UiController.EnrollmentDateGroup>
Then the entire ViewModel Folder can be eliminated. The concept of the Viewmodels are now included in Features.
Hi Jimmy,
I have very straightforward create action in my controller. After creation I want to redirect to the edit action so the user can continue to edit the newly created item. However the RedirectToActionJson doesn't seem to work properly even though stepping through the code the edit action is being called but the redirection to the edit URL still indicates the create action (/SomeAction/Create) when I would have expected /SomeAction/Edit/[new id]
Could it be something to do with some StructureMap "magic" around ending the request (StructureMapScopeModule) because I'm using Autofac?
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create(CreateEdit.Command command)
{
var id = _mediator.Send(command);
return this.RedirectToActionJson(c => c.Edit(new CreateEdit.Query { Id = id }));
}
public ActionResult Edit(CreateEdit.Query query)
{
var model = _mediator.Send(query);
return View("CreateEdit", model);
}
Hello, I am using Contoso University and I require notifications for individual modules, however, this notification will be similar throughout the application, so we are wondering if we can create one generic notification that multiple modules can share?
Hey Jimmy,
I've been using MediatR on a couple projects for the last 6 months and love it.
I've seen in many of your examples that you use nested types often for encapsulating your commands/queries. FxCop flags the CA1034 warning when using this pattern. Is that CA1034 rule anything we should be concerned about when using MediatR?
Thanks!
I get an error “The highlighted fields are required to submit this form” which is found in the javascript function showSummary of \js\site.js (line 42).
I don’t know enough of JavaScript to figure out how to debug it, nor do I know enough of your approach to building ASP.Net MVC web apps (but am definitely trying to learn as it looks very cool)
Thanks,
John Marsing
Unable to create an instructor because of a null reference throwing an error message.
Not sure what causes this, but likely due to having a custom controller factory, the routes are no longer case insensitive.
For example, if you create a /Features/Foo/UiController, with a Bar action, and request it via URL /foo/bar, this will return 404, but requests to /Foo/Bar work.
I was under the impression that you (@jbogard) was rather against the notion of using Automapper to map from DTOs back into an Entity/Domain object.
However, this sample is filled with that usage, where you take in a Command object (a DTO) and map it to the EF entity.
Why did you use this approach? Just for the sake of "learning". Would you actually do it this way in "real life"?
For example, if the user should only be able to view their own courses, how do you pass their identity back to the command or query handler? Do you just append it to the command/query prior to calling the handler like so?
public ViewResult Index(Index.Query query)
{
query.UserId = User.Identity.Name;
var model = _mediator.Send(query);
return View(model);
}
My current use case is that a user has a Scope property that denotes the highest level of organizational data they can access. This is a hierarchical structure going from Enterprise > Region > Site. If they have enterprise, they can filter on any site, if they only have Region 1, they can only filter on sites under Region 1, if it is Site 3, only Site 3 data is available.
for example what would this look like in AF?
private static IElementGenerator<T> GetGenerator<T>(T model) where T : class
{
var library = StructuremapMvc.ParentScope.CurrentNestedContainer.GetInstance<HtmlConventionLibrary>();
return ElementGenerator<T>.For(library, t => StructuremapMvc.ParentScope.CurrentNestedContainer.GetInstance(t), model);
}
Hi Jimmy, Would you have an idea of how to convert this code to use the ASP.NET Core dependency injection code?
private static IElementGenerator<T> GetGenerator<T>(T model) where T : class
{
var library =
StructuremapMvc.ParentScope.CurrentNestedContainer.GetInstance<HtmlConventionLibrary>();
return ElementGenerator<T>.For(library, t => StructuremapMvc.ParentScope.CurrentNestedContainer.GetInstance(t), model);
}
According to https://msdn.microsoft.com/en-us/library/hh510202(v=sql.120).aspx the name of SQL Express 2014 automatic instance is MSSQLLocalDB and not V12.0.
I would recommend that the web.config shipped be updated to use this. More likely to run right out of the box.
Change:
TO
@jbogard, you've written that the domain model could receive a command for changes (and here), but I've not seen that combined with MediatR usage. In this project you use AutoMapper to apply the message externally per-property, and the models classes don't receive message objects through functions on them.
Does it make sense to be receiving the IAsyncRequest
derived commands/requests in the domain model?
In my applications, I keep the domain models in a separate assembly so they can be shared with back-end asynchronous processes that don't run in the web context.
Should the non-web portion of the features (request, handler, response) live in the domain model assembly? Should there be domain model specific commands that are mapped to when needed from the IAsyncRequest
commands after validation; keeping the features in the web project?
Thanks in advance.
Error 970 The type or namespace name 'roundhouse' could not be found (are you missing a using directive or an assembly reference?) g:\Plastic\JBogardContosoUniversity\src\IntegrationTests\LocalDbFactory.cs 7 11 IntegrationTests
This currently relies on version 3.0.0.187 of HtmlTags but 3.0.0.186 is the latest one available on Nuget.
It seems that Mapping.AssertConfigurationIsValid() is missing in the project. Also, I believe it would throw an exception due to unmapped members, so might it be missing on purpose?
Hello,
I have been looking at Contoso University and I have a question:
How do you deal with refilling the model helper properties after being submitted with errors?
I am talking about filling SelectLists or the data which the SelectLists depends on?
Thank You,
Miguel
Any of you clever chaps ever done this?
I use AF in all my projects and would really like to see an AF version.
I'm curious to understand, given this implementation, how you recommend handling the scenario where a message (e.g. queue) needs to be dispatched, ala domain events style, from a command handler, but only after the transaction is committed.
The DB transaction is being committed or rolled back via the MVC action filter's OnActionExecuted
, which uses service locator to get the DbContext
, and call the CloseTransaction
. In other words, the transaction commit is being done outside the command handler. However, I'd like to dispatch an event message from the command only when the transaction is committed successfully, and from the command handler, I have no way of knowing when the transaction is committed.
Any thoughts on this?
Hi Jimmy,
I'm trying to create a select list that's not bound to EF. I want to have something like this:-
public static HtmlTag Select<T>(this HtmlHelper<T> helper, Expression<Func<T, object>> expression)
where T : class
{
var generator = GetGenerator(helper.ViewData.Model);
return generator.SelectFor(expression, "Select");
}
But I can't figure out how to do it. Would you by chance have a spare minute to help?
Hi Jimmy, I've been reading you articles about templates and like the way you did the FormBlock code. However, I can't seem to get a textarea to display. I've added [DataType(DataType.MultilineText)] to my model property but it seems to ignore it. Should I extend your example and create a specific "TextAreaBlock" or something else?
I'm adapting this pattern in a test app I'm developing and I'm wondering if it's possible to use MVC's attribute routing? I'm not having much luck, I just get a 404 if I remove the convention-based routing. Any ideas?
MvcTransactionFilter works only for SchoolContext.
public class MvcTransactionFilter : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// Logger.Instance.Verbose("MvcTransactionFilter::OnActionExecuting");
var context = StructuremapMvc.ParentScope.CurrentNestedContainer.GetInstance<SchoolContext>();
context.BeginTransaction();
}
...
}
Is there a way to make MvcTransactionFilter work for multiple datacontexts ?
By the way the multiple contexts may want to share the same transaction scope.
Ought to do some cleanup and remove that application.hosts file before so it won't get pulled with future clones.
FormBlocks do not work with v4 of HtmlTags. It spits out raw HTML instead of rendered labels and controls.
Hi,
I have question about the syntax you used in some of the Index pages. For instance, Course - Index
There is a foreach
loop that creates a table row for each Course, but instead of using the item
variable you use an indexer to access the properties of that Course.
@Html.Display(modelItem => modelItem.Courses[i].CourseID)
What is the reason for doing it like this?
Thanks for helping me out.
How would you go about adding support for Areas? I think it would make sense for a folder structure similar too
Will you accept pull requests to migrate the other feature folders to MediatR as you have done with Departments?
And Happy Birthday!
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.