Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
crashdome
Jun 28, 2011

mastersord posted:

I apologize in advance for sounding like an inexperienced moron. I am in the process of trying to upgrade all our in-house code from VB6 to VB.NET and since we're so small, no one really knows anything about visual Studio past VS99 or whatever was the last VB6 release. I am trying to catch up on the last 10-15 years of advances on my own.

Why does it seem like everyone is making web apps as opposed to local apps? In my shop we have no need for any special internet applications outside of the browser and with HIPAA we have little to no reason to unnecessarily expose our data to the internet more than required.

Am I mis-interpreting what MVC does?

Welcome to present day.

Here's what you're going to learn:

VB.NET is not even remotely close to VB6
Your going to have to completely rewrite everything.
Your concept of programming is antiquated and everyone hates it and if you continue to rewrite your software using old methods, young developers will never want to maintain your software.

I'm not trying to be snarky or cruel but, as a person hired to update VB6 programs to present day technology, it is going to take your VB6 devs well over a year to come to grips with everything new. You'll be far more comfortable and it will be far more cost effective if you hired up-to-date developers and just let them build what you need for you.

Internet != HIPAA violation
Web technology is far more flexible. Personally I build and prefer standard applications (now WPF) but even I have to embrace there's always going to be overlap between Web and Native applications.

Adbot
ADBOT LOVES YOU

raminasi
Jan 25, 2005

a last drink with no ice

mastersord posted:

I apologize in advance for sounding like an inexperienced moron. I am in the process of trying to upgrade all our in-house code from VB6 to VB.NET and since we're so small, no one really knows anything about visual Studio past VS99 or whatever was the last VB6 release. I am trying to catch up on the last 10-15 years of advances on my own.

Why does it seem like everyone is making web apps as opposed to local apps? In my shop we have no need for any special internet applications outside of the browser and with HIPAA we have little to no reason to unnecessarily expose our data to the internet more than required.

Am I mis-interpreting what MVC does?

The differences between VB6 and VB.NET are completely orthogonal to whether you want a web app or not. Does your current application serve web pages? Then MVC will help you do that. If not, then don't even worry about it.

And I've never used VB6 myself, but everything I've heard about it describes it as essentially a completely different language from VB.NET. VB6->VB.NET isn't an "upgrade," it's a complete rewrite.

Sedro
Dec 31, 2008

mastersord posted:

Why does it seem like everyone is making web apps as opposed to local apps? In my shop we have no need for any special internet applications outside of the browser and with HIPAA we have little to no reason to unnecessarily expose our data to the internet more than required.
Web apps don't have to be exposed to the internet

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
In addition to everyone else's excellent points, the draw of web apps these days is multi-platform support. People don't just have desktop PCs anymore -- they have phones and tablets as well. Writing your desktop application so it runs natively on every platform is (probably) more difficult than writing a web application.

Of course, web apps have a whole different nightmare of browser compatibility issues, but it's probably easier to fix those issues than ensure that your desktop application can run on Windows (XP? 7? 8? 10?), OSX, iPhones/iPads, Android phones, Windows phones, and so on.

If your organization is standardized on one OS and the rest don't matter, and you don't think anyone will ever need or want to use your application from a phone or tablet, then yeah, by all means, keep it as a desktop application.

RICHUNCLEPENNYBAGS
Dec 21, 2010

mastersord posted:

I apologize in advance for sounding like an inexperienced moron. I am in the process of trying to upgrade all our in-house code from VB6 to VB.NET and since we're so small, no one really knows anything about visual Studio past VS99 or whatever was the last VB6 release. I am trying to catch up on the last 10-15 years of advances on my own.

Why does it seem like everyone is making web apps as opposed to local apps? In my shop we have no need for any special internet applications outside of the browser and with HIPAA we have little to no reason to unnecessarily expose our data to the internet more than required.

Am I mis-interpreting what MVC does?

It's cross-platform, you're less likely to build some software incompatible with the new version of Windows keeping you from upgrading or whatever, and deployment is easy. You don't have to use this stuff over the Internet if you don't need to. Advances both in JS interpreters and in JS libraries also make it a lot more plausible to do things in the browser that used to be pretty difficult.

That said, working with MVC will be an even bigger shift in thinking than jumping into .NET. A lot of Web stuff written by mostly-desktop guys ends up being pretty rough.

Ithaqua posted:

Of course, web apps have a whole different nightmare of browser compatibility issues, but it's probably easier to fix those issues than ensure that your desktop application can run on Windows (XP? 7? 8? 10?), OSX, iPhones/iPads, Android phones, Windows phones, and so on.
Also, if your needs can be mostly served by stable, popular libraries, someone else has done a lot of that work for you.

RICHUNCLEPENNYBAGS fucked around with this message at 04:50 on Jan 12, 2015

Calidus
Oct 31, 2011

Stand back I'm going to try science!
When you're responsible your writing and deploying applications, managing one internal IIS server become much better than dealing with desktops.

mastersord
Feb 15, 2001

Gold Card Putty Fan Club
Member Since 2017!
Soiled Meat
First off, thank you for all your responses!

From my experiences so far, i know vb.net and vb6 are different. The differences are more prevalent in how form controls work and also going from ADODB to ADO.NET.

wilderthanmild
Jun 21, 2010

Posting shit




Grimey Drawer
I'd suggest that if you're looking at a desktop application in vb.net you shy away from using winforms and learn to properly use WPF if possible. As said before, you'll need to rewrite the majority of your code anyway, so I'd really suggest starting with the more modern approach using MVVM and WPF rather than a vb.net winforms application made to mimic a vb6 application. A few pitfalls aside(The Datagrid and Browser controls have been really annoying to work with in my opinion), WPF seems like such an improvement after spending few years with a vb.net winforms app built off a vb6 forms app.

Not that it's impossible to make a good winforms application, I'd just say it might be worth the effort to use the more modern approach.

Calidus posted:

When you're responsible your writing and deploying applications, managing one internal IIS server become much better than dealing with desktops.

Oddly enough, this has been a fairly easy for me to handle using a ClickOnce deployment with a publish directory on a shared drive. ClickOnce seems to suck at a lot of things, but internal deployments have been really easy using it.

wilderthanmild fucked around with this message at 19:19 on Jan 12, 2015

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

Yeah VB6 more logically progresses to WPF/WinForms unfortunately, in that you're still dealing with relatively familiar form elements, events, triggers, etc. That said, making a WPF app in this day and age still feels a bit weird, but it might work out for you. I actually went from VB6 -> ASP Classic -> ASP.NET -> VB.NET, but I was always more of a database logic guy than an interface guy so it was mostly a positive experience. I'm trying to remember what the biggest gotchas coming out of VB6 were, but they mostly relate to declaring variables and scope, not having to deal with ODBC for database (hallelujah!). Other than that IF THEN is still IF THEN, FOR NEXT is still FOR NEXT, etc. Oh and always use GOTO.

crashdome
Jun 28, 2011

mastersord posted:

The differences are more prevalent in how form controls work and also going from ADODB to ADO.NET.

Just wait until you see LINQ and Lambda Expressions!

mastersord
Feb 15, 2001

Gold Card Putty Fan Club
Member Since 2017!
Soiled Meat
My biggest hurdle thus far has been going from ADODB to ADO.NET for database stuff. Mainly problems with direct SQL calls that should've been done as database objects (views, functions, stored procedures).

For us the ADODB recordset did everything once you gave it a connection and a command. In ADO.NET, the recordset is split into several objects that have to be linked together (data adapter populates a data set which contains one or more data tables). I wrote a class to manage these relationships, after having problems with the interop libraries trying to support ADODB.

I should be using stuff like Entity Framework, but the learning curve kinda scared us away.

Space Whale
Nov 6, 2014
Working on an EF project. I've only worked on one before, and it was set up so I could easily get to the designer, etc. Welp the one I'm on now is apparently not.

I feel lost as poo poo and generally don't know how in VS2013 you do the magic with your data tools to set up your data contexts; I've only ever used the designer. What's a good place to poke around and make sure everything is up to date with db changes and such?

Also it uses the UnitOfWork pattern and ninject. :psyduck: What happened to just using ADO.NET and a folder of business objects? Imposter syndrome is coming on something fierce.

bpower
Feb 19, 2011

Space Whale posted:

Working on an EF project. I've only worked on one before, and it was set up so I could easily get to the designer, etc. Welp the one I'm on now is apparently not.

I feel lost as poo poo and generally don't know how in VS2013 you do the magic with your data tools to set up your data contexts; I've only ever used the designer. What's a good place to poke around and make sure everything is up to date with db changes and such?

Also it uses the UnitOfWork pattern and ninject. :psyduck: What happened to just using ADO.NET and a folder of business objects? Imposter syndrome is coming on something fierce.


mastersord posted:

My biggest hurdle thus far has been going from ADODB to ADO.NET for database stuff. Mainly problems with direct SQL calls that should've been done as database objects (views, functions, stored procedures).

For us the ADODB recordset did everything once you gave it a connection and a command. In ADO.NET, the recordset is split into several objects that have to be linked together (data adapter populates a data set which contains one or more data tables). I wrote a class to manage these relationships, after having problems with the interop libraries trying to support ADODB.

I should be using stuff like Entity Framework, but the learning curve kinda scared us away.

I was in exactly the same position as your guys two months ago ("DID ADO AND SQL STOP WORKING OR SOMETHING ?????!!!!") See pages 34/36 of this very thread. I got great advice there. You need learn a new thing, sorry. Go through the tutorials for EF, Hibernate and Dapper. Pick one and learn it. I highly recommend trying EF first using videos on Pluralsight.They're what made everything click for me. There is a steep learning curve but with 3 or 4 days dedicated study you can start being productive.

Its been great for me,dev is so much quicker now that I'm using EF.

I implemented a unit of work pattern as an exercise but I just couldn't see the benefit of it on top of EF. Theres another great video on Pluralsight called "Building a application framework in .net mvc" or something like that. and he use DI in a really practical way to keep the code clean, and to implement cross cutting concerns.

Im not shilling for Pluralsight, I just found them very useful.

RICHUNCLEPENNYBAGS
Dec 21, 2010

Space Whale posted:

Working on an EF project. I've only worked on one before, and it was set up so I could easily get to the designer, etc. Welp the one I'm on now is apparently not.

I feel lost as poo poo and generally don't know how in VS2013 you do the magic with your data tools to set up your data contexts; I've only ever used the designer. What's a good place to poke around and make sure everything is up to date with db changes and such?

Also it uses the UnitOfWork pattern and ninject. :psyduck: What happened to just using ADO.NET and a folder of business objects? Imposter syndrome is coming on something fierce.

EF is unit of work!

Wardende
Apr 27, 2013
I once wrapped my EF implementation inside a UnitOfWork/Repository abstraction because... ... Anyway, you don't need to do that. The DbContext already implements those patterns.

mastersord
Feb 15, 2001

Gold Card Putty Fan Club
Member Since 2017!
Soiled Meat
Sounds like a good plan and I will give it a shot. My team is very small (meaning my boss and myself). I mainly handle the coding aspects and he handles the database stuff but I'm pretty fluent in both (or at least i like to think so).

RICHUNCLEPENNYBAGS
Dec 21, 2010

Wardende posted:

I once wrapped my EF implementation inside a UnitOfWork/Repository abstraction because... ... Anyway, you don't need to do that. The DbContext already implements those patterns.

The only reason to do it is testing, I think, but EF7 will have an in-memory provider for this exact scenario.

Wardende
Apr 27, 2013
Thank goodness. I also once wrote a very complicated Moq framework of EF that was only about 70% effective, so I'm pleased to hear about this.

Space Whale
Nov 6, 2014
The thing for me is I've done data-first, and code-first is just "huh? What does the contexts? Where's the magic?" My architect is going to give me and other developers a proper walk-through today, so I'm happy with that.

About UoW in your EF so you can work while you work: It's only used to call a .Commit() method in a POST verb. We're using all this magical poo poo in a webapi controller; every GET verb is just touching the repository for any given context. Is that sensible?

TheEffect
Aug 12, 2013
Can I use a wildcard to search for directories that start with a certain string? Pseudo-code example-

If *DirExists*("C:\Program Files\ABC" & *Wildcard here* & ".txt") Then
*Do something*

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

TheEffect posted:

Can I use a wildcard to search for directories that start with a certain string? Pseudo-code example-

If *DirExists*("C:\Program Files\ABC" & *Wildcard here* & ".txt") Then
*Do something*

Directory.EnumerateDirectories

TheEffect
Aug 12, 2013

Excellent, thank you!

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal
Anyone with Lucene experience know how I can speed this up?
C# code:
for (int i = 0; i < localCategoryIds.Count; i++)
{
    string catId = categoryIds[i].ToString();

    _queryParser = new QueryParser(Version.LUCENE_30, "Prod_Category1", _analyzer);
    Query categoryQuery = _queryParser.Parse(catId);
    filterQuery.Add(categoryQuery, Occur.SHOULD);

    _queryParser = new QueryParser(Version.LUCENE_30, "Prod_Category2", _analyzer);
    categoryQuery = _queryParser.Parse(catId);
    filterQuery.Add(categoryQuery, Occur.SHOULD);

    _queryParser = new QueryParser(Version.LUCENE_30, "Prod_Category3", _analyzer);
    categoryQuery = _queryParser.Parse(catId);
    filterQuery.Add(categoryQuery, Occur.SHOULD);

    _queryParser = new QueryParser(Version.LUCENE_30, "Prod_Category4", _analyzer);
    categoryQuery = _queryParser.Parse(catId);
    filterQuery.Add(categoryQuery, Occur.SHOULD);

    _queryParser = new QueryParser(Version.LUCENE_30, "Prod_Category5", _analyzer);
    categoryQuery = _queryParser.Parse(catId);
    filterQuery.Add(categoryQuery, Occur.SHOULD);
}
Currently I'm running into a huge bottleneck here with 143 localCategoryIds. The results are zippy enough after the query is built, but this loop is taking around 5-7 seconds at its worst, so I'm guessing we're doing something incorrectly.

Knyteguy fucked around with this message at 23:19 on Jan 13, 2015

Sedro
Dec 31, 2008
Pull the QueryParser construction out of the loop? Also you can probably use MultiFieldQueryParser. Also consider whether you even need category IDs to be analyzed

RICHUNCLEPENNYBAGS
Dec 21, 2010

Space Whale posted:

The thing for me is I've done data-first, and code-first is just "huh? What does the contexts? Where's the magic?" My architect is going to give me and other developers a proper walk-through today, so I'm happy with that.

About UoW in your EF so you can work while you work: It's only used to call a .Commit() method in a POST verb. We're using all this magical poo poo in a webapi controller; every GET verb is just touching the repository for any given context. Is that sensible?

I have used EF almost daily for like a year, so I feel like I should be able to help, but I don't really understand what you're saying.

Space Whale
Nov 6, 2014

RICHUNCLEPENNYBAGS posted:

I have used EF almost daily for like a year, so I feel like I should be able to help, but I don't really understand what you're saying.

I went from the use the designer, create an EDMX file, data-first EF world, to this babby snowflake (the crux of the problem) code-first mdoel which has custom UoW wrappers and hand written contexts AND uses automapper. I think my problem is learning multiple libraries and our convoluted architecture at the same time.

mortarr
Apr 28, 2005

frozen meat at high speed
I'm writing my first web api, and each controller has only get, put, post etc methods, which seems like it's going to result in a large number of controllers over time, because there are quite a few types of object to interact with, and different systems interact with the same object in different ways.

Is this the modern way to do things or am I missing the point?

Actually, just typing this out made me think I should reduce the number of controllers and have overloads on the verb methods, but even so I feel like I'm doing something wrong.

EssOEss
Oct 23, 2006
128-bit approved
Can you present some actual example or analogy of the controllers/objects/methods you envision creating? It is not really possible to advise on such a topic in the abstract.

Knyteguy
Jul 6, 2005

YES to love
NO to shirts


Toilet Rascal

Sedro posted:

Pull the QueryParser construction out of the loop? Also you can probably use MultiFieldQueryParser. Also consider whether you even need category IDs to be analyzed

Thanks. I made the changes mentioned.

It turns out that this wasn't the bottleneck after all however. The lag time in running through the loop was just a problem specific to my development PC running out of processing power. The actual problem turned out to be that the base software we've built upon is terribly inefficient (which we've known for awhile), and it was a problem stemming from the core code. It was trying to pull 60,000 products from Lucene all at once and just eating up resources like crazy.

Drastic Actions
Apr 7, 2009

FUCK YOU!
GET PUMPED!
Nap Ghost

mortarr posted:

I'm writing my first web api, and each controller has only get, put, post etc methods, which seems like it's going to result in a large number of controllers over time, because there are quite a few types of object to interact with, and different systems interact with the same object in different ways.

Is this the modern way to do things or am I missing the point?

Actually, just typing this out made me think I should reduce the number of controllers and have overloads on the verb methods, but even so I feel like I'm doing something wrong.

Based on what you wrote, I think you're doing this:

C# code:
public void Get(SomeObject awesomeObject)
        {
          // Something in here
        }
public void Post(SomeObject awesomeObject)
        {
          // Something in here
        }
Your methods can have attributes for what they accept, so you can have

C# code:
[HttpGet]
public void SomeKindOfGetRequest(SomeObject awesomeObject)
        {
		// Get Request
        }
[HttpPost]
public void SomeKindOfPostRequest(SomeObject awesomeObject)
        {
		// Post Request
        }
and so on. So your controllers can have multiple Get/Post/Delete/Put requests in them.

mortarr
Apr 28, 2005

frozen meat at high speed

mortarr posted:

I'm writing my first web api, and each controller has only get, put, post etc methods, which seems like it's going to result in a large number of controllers over time, because there are quite a few types of object to interact with, and different systems interact with the same object in different ways.

Is this the modern way to do things or am I missing the point?

Actually, just typing this out made me think I should reduce the number of controllers and have overloads on the verb methods, but even so I feel like I'm doing something wrong.

Looks like i was missing the point of rest/web api to some extent. I had controllers named around the action like DocumentRegistration, DocumentCount and DocumentList. Refactored around resource (following more research), so I have Document and Documents controllers, with count or list operations selected via config object now.

Typing on my phone sucks, got no code examples sorry.

ljw1004
Jan 18, 2005

rum

mortarr posted:

I'm writing my first web api, and each controller has only get, put, post etc methods, which seems like it's going to result in a large number of controllers over time, because there are quite a few types of object to interact with, and different systems interact with the same object in different ways.
Is this the modern way to do things or am I missing the point?
Actually, just typing this out made me think I should reduce the number of controllers and have overloads on the verb methods, but even so I feel like I'm doing something wrong.

Shouldn't you be writing stuff like this?
code:
<Route("api/files/{uuid}")>
Async Function GetFilesAsync(uuid As String, auth As String) As Task(Of ListOfFiles)

... and so on for the other possible routes
I'm not very good at WebAPI. I believe this <Route> attribute style of doing it comes in WebAPI 2. I believe that you can just write them all and they don't have to be in the controller type.

bobua
Mar 23, 2003
I'd trade it all for just a little more.

I have 2 buttons on a wpf window(play and pause). If I hit pause, then close the window, everything is fine. If I close the window while still playing, my program locks up indefinitely(a third party api call that never returns).

In the Window.Closing event...
code:
Camera.Pause();
Camera.RevokeFrames(); <--never returns
In the Pause button event...
code:
Camera.Pause();
Is the window.closing event run on another thread or something I don't know about? I've also tried putting a 2 second thread.sleep in between the pause and revokeframes command, no luck.

RICHUNCLEPENNYBAGS
Dec 21, 2010

ljw1004 posted:

Shouldn't you be writing stuff like this?
code:
<Route("api/files/{uuid}")>
Async Function GetFilesAsync(uuid As String, auth As String) As Task(Of ListOfFiles)

... and so on for the other possible routes
I'm not very good at WebAPI. I believe this <Route> attribute style of doing it comes in WebAPI 2. I believe that you can just write them all and they don't have to be in the controller type.

Why wouldn't you just configure the routes properly instead of attributing each one? The default is to just use the controller name and HTTP verb but I hate that; I just configured it with MVC-style routing.

Space Whale posted:

I went from the use the designer, create an EDMX file, data-first EF world, to this babby snowflake (the crux of the problem) code-first mdoel which has custom UoW wrappers and hand written contexts AND uses automapper. I think my problem is learning multiple libraries and our convoluted architecture at the same time.

I'm still not sure I understand, but the controller is instantiated, runs an action method, and is disposed with each request. You can work out how to do this, but you want an entity context to be spun up with each request and disposed at the end. I use a DI container to do this but you can add the context as an instance field and dispose it in the controller's dispose method or you can jsut use a using statement.

RICHUNCLEPENNYBAGS fucked around with this message at 03:15 on Jan 15, 2015

Space Whale
Nov 6, 2014
I'll give an example:

Our WebAPI controllers have in the constructor's parameters at least one IRepository<BizObjectType> foo and one IUnitOfWorkFacotry uowFactory. I guess the architect reallly, really likes UoW and hand written contexts?
code:
        public BarController(IUnitOfWorkFactory uowFactory,
                               IRepository<Bar> barRepository)
        {
            UnitOfWork = uowFactory.Create("Bar");
            BarRepository = barRepository;
        }
And the way we'd query the db is like this:

code:

        [Queryable]
        public IQueryable<FooModel> Get()
        {
            var result = FooRepository.GetAll()
                                             .Project<Foo>()
                                             .To<FooModel>();

            foreach (var foo in result)
            {
                ModelUrlFactory.Populate(foo);
            }

            return result;
        }


And actually saving anything to the db:

code:
public IHttpActionResult Post([FromBody]BarModel value)
        {
            if (!ModelState.IsValid)
                return BadRequest();

            if (value.Id != 0)
            {
                var existing = BarRepository.Get(m => m.Id == value.Id);

                if (existing != null)
                    return BadRequest(string.Format("User {0} already exists.", value.Id));
            }

            var bar= new Bar
            {
                BarAccessToken = value.AccessToken,
                InstallDate = value.InstallDate,
                baz = new Baz
                {
			//properties here 
                },
            };

            BarRepository.Add(bar);

            UnitOfWork.Commit();

            return Ok(bar.Id);
        }
It just seems totally unnecessary. Why not just use EF as EF? I've heard it's something to do with "Scaling" and "we did it wrong in the past with one big context," but I thought EF can just do that and you don't need to wrap EF in another layer of UoW.

magnetic
Jun 21, 2005

kiteless, master, teach me.
.NET MVC 4.5 Entity framework (Web Api)
code:
           SqlParameter badgeID = new SqlParameter();
            badgeID.ParameterName = "@BadgeID";
            badgeID.SqlDbType = System.Data.SqlDbType.Int;
            badgeID.SqlValue = badge;

           ....//some more params

            SqlParameter[] parameters = { badgeID, UsersID, languageID, usersQuizzesID };

            int ret = context.Database.ExecuteSqlCommand("[dbo].[UsersQuizzesCreate] @BadgeID , @UsersID, @languageID, @usersQuizzesID              OUTPUT ",
                         parameters);
            return ret;
Question 1:
When executing this code I look at Sql Profiler and see that that command issued is sp_executesql 'sqlstatement stuff'.
is there a way to have it invoke the sproc directly?

Question 2:
Am I blind or are stored procedure output parameters wonky in Entity Framework?

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

I'm not a MVC/Entity expert at all, but I think that sp_executesql is being called because you're passing in a string and having it executed directly, and the server at run time has no idea if you've passed in a proc or a dynamic string. I have no exposure to the framework but I'd expect the sproc to only get explicitly called the server knows it directly. Again, never coded for it but I'd expect something like:
code:
Dim sprocUserQuizzesCreate as New SomethingObjectEFUnderstands

sprocUserQuizzesCreate.ProcedureName = "dbo.UsersQuizzesCreate"
sprocUserQuizzesCreate.Params.Add("@BadgeID",555)
Dim dsThinger as DataSet = sprocUserQuizzesCreate.Execute()

Malcolm XML
Aug 8, 2009

I always knew it would end like this.
Please use attribute based routing and have your controllers use reasonable method names.

bpower
Feb 19, 2011

Space Whale posted:

I'll give an example:

Our WebAPI controllers have in the constructor's parameters at least one IRepository<BizObjectType> foo and one IUnitOfWorkFacotry uowFactory. I guess the architect reallly, really likes UoW and hand written contexts?
code:
        public BarController(IUnitOfWorkFactory uowFactory,
                               IRepository<Bar> barRepository)
        {
            UnitOfWork = uowFactory.Create("Bar");
            BarRepository = barRepository;
        }
And the way we'd query the db is like this:

code:

        [Queryable]
        public IQueryable<FooModel> Get()
        {
            var result = FooRepository.GetAll()
                                             .Project<Foo>()
                                             .To<FooModel>();

            foreach (var foo in result)
            {
                ModelUrlFactory.Populate(foo);
            }

            return result;
        }


And actually saving anything to the db:

code:
public IHttpActionResult Post([FromBody]BarModel value)
        {
            if (!ModelState.IsValid)
                return BadRequest();

            if (value.Id != 0)
            {
                var existing = BarRepository.Get(m => m.Id == value.Id);

                if (existing != null)
                    return BadRequest(string.Format("User {0} already exists.", value.Id));
            }

            var bar= new Bar
            {
                BarAccessToken = value.AccessToken,
                InstallDate = value.InstallDate,
                baz = new Baz
                {
			//properties here 
                },
            };

            BarRepository.Add(bar);

            UnitOfWork.Commit();

            return Ok(bar.Id);
        }
It just seems totally unnecessary. Why not just use EF as EF? I've heard it's something to do with "Scaling" and "we did it wrong in the past with one big context," but I thought EF can just do that and you don't need to wrap EF in another layer of UoW.

Ok there's nothing inherently wrong with the UoW pattern or the repository pattern, but a lot of people, you included, have pointed out its a needless abstraction of EF.

// this guy loving hates the repo patteren
http://ayende.com/blog/search?q=respository

// another
https://cockneycoder.wordpress.com/2013/04/07/why-entity-framework-renders-the-repository-pattern-obsolete/

//another
http://tech.pro/blog/1191/say-no-to-the-repository-pattern-in-your-dal


// Unit Of work
The anti UoW stuff is a little harder to find probably because its not so widely used in demos . A reason to implement UoW on top of EF is to abstract away the specific ORM, not incase you decide to change orm but for testing. Are you guys Test-First? That might be a reason for UoW.

Why aren't' you asking the "architect" why you're using this stuff? You should have the confidence to say "I don't understand this, please explain this decision".

Also I don't understand why you're annoyed by the "hand-written" dbcontext. Surely you've come across databases with schemas "hand-written" in SQL. Your main problem is new concept overload. Take your time and learn the fundamentals of the new tech.

Adbot
ADBOT LOVES YOU

Space Whale
Nov 6, 2014
Oh I did ask, and I'm learning. I value second opinions, and here I'm not asking someone I work with.

Yes, we're doing unit tests as of right before I started, which is why it's still very new to the team.

Thanks for the breakdown!

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply