Hot answers tagged

24

Don't think yet about the tool that you are going to use. You can do DI without an IoC Container. First point: Mark Seemann has a very good book about DI in .Net Second: composition root. Make sure that the whole set up is done on the entry point of the project. Rest of your code should know about injections, not about any tool that is being used. Third:...


9

There are two parts to your question - how to implement DI properly, and how to refactor a large application to use DI. The first part is answered well by @Miyamoto Akira (especially the recommendation to read Mark Seemann's "dependency injection in .net" book. Marks blog is also a good free resource. The second part is a good deal more complicated. A ...


4

A simple format for storing tabular data is CSV. Attach it as a resource, just like you planned to do with the excel document. In theory you can even edit it using standard spreadsheed software, though there will problems with that: CSV does not encode types, so Excel will use heuristics to detect e.g. dates, which may corrupt data that looks like a ...


4

Since there is a constructor overload that takes an array of characters, this should work: var bar = new string(foo.Select(x => x).ToArray()); Which pretty much eliminates the need for another constructor overload, as the proposed overload would essentially have to do the same thing. Eric Lippert often discusses why certain features don't make it ...


3

If you truly want to keep all of it separate, you could create your own TransactionScope interface and use that in your Create Method. The implementation of said interface then uses the SqlTransactionScope to do the "real" work.


2

What you need is a Unit of Work for your Repositories. The Unit of Work would have an interface similar to public interface IUnitOfWork { ITransaction Start(); void Commit(); void RollBack(); } then your save method on IOrderDataService and IOrderLineDataService would take an ITransaction, becoming: public interface IOrderDataService { ...


1

You want to create a user control. You can predefine the layout, much like you would with a Form, and then create and add a new instance of the control to a Form, just like you'd dynamically add a new label, text box, etc.


1

I think the solution you have is the right one. If the report metadata is declared in one place, it seems like that would be fairly readable? However, one way to make it more readable would be to create a builder for the ReportMetaData class. Here's an example for Java (though should apply equally well to C#): http://www.informit.com/articles/article.aspx?p=...


1

On the one hand we expect convenience, on the other strict OOP principles being applied. If you implement too many convenient overloads, you will soon be implementing a universal type converter in a string class. And then something else. I guess keeping things mean and lean and sticking to the single responsibility principle outweighed the need for more ...


1

This constructor takes an array of chars as its input. For your use case, you can simply: var bar = new string(foo.Select(x => x).ToArray()); If you wanted a rationale, you could say that the lazy-loading behavior of the IEnumerable does not give you any added benefit here since you need to read the whole thing anyway to create the string. Whether ...


1

If you want to avoid SqlTransaction you may use TransactionScope from System.Transactions. This will have the added benifit that any systems that use MSDTC may use the same transaction. It also decouples your database from your business layer allowing the business layer to logically group your transactional data.


1

Persisting data to a date store (DB or other) isn't truly business logic, so I would push the SqlTransactionScope as close to the data layer as possible as it is controlling how the data is persisted/transacted. Your last method of: void Save(Order order, List<OrderLine> orderlines) This makes the most sense as the SqlTransactionScope would be ...


1

First I want to mention that you are making this significantly harder on yourself by refactoring an existing project rather than starting a new project. You said it is a large application, so pick a small component to start with. Preferably a 'leaf-node' component that is not used by anything else. I don't know what the state of the automated testing is on ...


1

The source to the method is now online: http://referencesource.microsoft.com/#mscorlib/system/string.cs


1

Starting in C# 6.0, getter-only auto properties have been added into the language. See here: https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C%23-6#getter-only-auto-properties. Here's an example: public class SomeClass { public int GetOnlyInt { get; } public int GetOnlyIntWithInitializer { get; } = 25; public SomeClass(int ...



Only top voted, non community-wiki answers of a minimum length are eligible